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

When I touch the part why doesn't it give me any coins?

Here is the script where I want it to give you 5 coins when you touch the part

local player = game.Players:GetPlayerFromCharacter()
script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		player.leaderstats:FindFirstChild("Coins")
		Coins.Value = 5
	end
end)

And then the leaderboard script

game.Players.PlayerAdded:Connect(function(player)
	local stats = Instance.new("IntValue",player)
	stats.Name = "leaderstats"
	
	money = Instance.new("IntValue",stats)
	money.Name = "Coins"
end)



1 answer

✓ Accepted answer

This isn't working because you are setting player outside of the touched event and with no parameter, which results in nil.

And Coins wasn't set to anything.

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        local Coins=player.leaderstats:FindFirstChild("Coins")
        Coins.Value = 5
    end
end)

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