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

Why Wont The Coin When i touch it change the leader board to 1 coin ?

local db = true
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") ~= nil then
		if db == true then
			db = false
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1
			script.Parent.Parent.Parent.Model:Destroy()
		end
	end
end)

error: 12:20:25.556 - Touched is not a valid member of Model

1 comment

0

make sure script.Parent is a part

1 answer

✓ Accepted answer

Change script.Parent to script.Parent.Part and use waitforchild just in case the leaderstats hasnt loaded yet

local db = true
script.Parent.Part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") ~= nil then
        if db == true then
            db = false
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            player:WaitForChild("leaderstats"):WaitForChild("Coins").Value = player.leaderstats.Coins.Value + 1
            script.Parent.Parent.Parent.Model:Destroy()
        end
    end
end)

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