简体   繁体   English

尝试在 roblox studio 中使用“leaderstats”错误索引 nil

[英]attempt to index nil with 'leaderstats' error in roblox studio

I'm making a game where you ram cars into houses and it unanchored the parts that are touched by a part in the front of the car.我正在制作一个游戏,你将汽车撞到房子里,它会解开汽车前部接触到的部分。 I want to have it so that whenever you unanchor a part, you get a coin我想拥有它,这样每当您取消锚定零件时,您都会得到一枚硬币

local HitPart = script.Parent

local function onTouch(otherPart)

    local player = otherPart.Parent

    if otherPart then

        local player = game.Players:FindFirstChild(otherPart.Parent.Name)

        if otherPart then

            game.Players.LocalPlayer.leaderstats.coins.Value = game.Players.LocalPlayer.leaderstats.coins.Value + 1 

        end

    end
end

HitPart.Touched:Connect(onTouch)

HitPart is the part that is touching the other parts. HitPart 是接触其他部分的部分。 However, I keep getting an attempt to index nil with 'leaderstats'" error. does anyone know what's wrong?但是,我不断尝试使用“leaderstats”错误来索引 nil。有谁知道出了什么问题?

It means it doesn't exist.这意味着它不存在。 If it does, make sure to get capitalization correct.如果是这样,请确保大小写正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM