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

My coin collect script won't work? PLEASE HELP SDFOJISJDOIFSDJ

I'm trying to make a coin collect script. Any help?

script.Parent.Touched:Connect(function(hit)
	local humanoid = hit:findFirstChild("Humanoid")
	if humanoid ~= nil then
		game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Coins.Value = game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Coins.Value + 1
		script.Parent.Transparency = 1
		script.Parent.CollectSound:Play()
		wait(script.Parent.CollectSound.TimeLength)
		script.Parent:Destroy()
	end
end)

1 answer

✓ Accepted answer

Easy fix, you just need to do, hit.Parent, instead of hit

script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:findFirstChild("Humanoid")
    if humanoid ~= nil then
        game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Coins.Value = game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Coins.Value + 1
        script.Parent.Transparency = 1
        script.Parent.CollectSound:Play()
        wait(script.Parent.CollectSound.TimeLength)
        script.Parent:Destroy()
    end
end)

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