script.Parent.Touched:Connect(function(plr, hit) local dude = hit.Parent local dudehuman = dude:FindFirstChild("Humanoid") dudehuman.Health = dudehuman.Health - 1 plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 1 wait(1) end)
Okay so, I er wanted to make ye function, but function made use of both plr
and hit
, and i've seen numerous scripts where thee put a comma between ze two thingys. My problem be Me think that it only made use of plr. Me reasoning is that I had yer index nil outyputy thingzy. Me know what that means. That means that it does not exist and thy game can't be thinking doing something if thy does not exist! here is me output error.
21:11:42.691 - Workspace.Part.Script:2: attempt to index nil with 'Parent'
.Touched
has only one argument, which is the part that touched it. If you want to get the player, you should do :GetPlayerFromCharacter
.
script.Parent.Touched:Connect(function(hit) local dude = hit.Parent local dudehuman = dude:FindFirstChild("Humanoid") local plr = game.Players:GetPlayerFromCharacter(dude) dudehuman.Health = dudehuman.Health - 1 plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 1 wait(1) end)