Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Did I do the function thing wrong?

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'

2 comments

1

I'm sorry for pirate talk. I just felt like speaking like a pirate.

1

¯_ (?)_/¯

1 answer

✓ Accepted answer

.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)

This discussion is preserved as it was. New answers, comments, and votes are closed.