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

Find the player who have touch the part ?

I wish that when the player touches the part he receives 10 cash, but my script does not work

function Touched(h)
    local player = h.Parent
    player.leaderboard.Cash.Value = 10
end

script.Parent.Touched:Connect(Touched)

1 answer

✓ Accepted answer

Use GetPlayerFromCharacter with Players

function Touched(h)
	local Player = game:GetService('Players'):GetPlayerFromCharacter(h.Parent) -- Find the client 
	if Player then
		Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 10 -- 100 + 10 = 110 and not 0 = 10
	end
end

script.Parent.Touched:Connect(Touched)

-- 2

script.Parent.Touched:Connect(function(h)
	local Player = game:GetService('Players'):GetPlayerFromCharacter(h.Parent) -- Find the client 
	if Player then
		Player.leaderstats.Cash.Value = Player.leaderstats.Cash.Value + 10 -- 100 + 10 = 110 and not 0 = 10
	end
end

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