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

Can't add value to leaderboard by touching a brick ?

So I want the player to receive +1 win when touching a brick, but I can't seem to make it work

script.Parent.Touched:Connect(function(Player)
local ls = Player.leaderstats
    if ls then
        ls.Wins.Value = ls.Wins.Value + 1
    end
end)

1 answer

✓ Accepted answer

Normally, another part can touch that part and trigger the Touched event and make the connected function assume that the part that was touched is the player; That'll not work, also the player object will not be the one that triggers the event and is returned, a part of the player's character does that.

You can use Players:GetPlayerFromCharacter, which is self-explanatory:

script.Parent.Touched:Connect(function(part)
    local player = game.Players:GetPlayerFromCharacter(part.Parent)
    if player then
         -- add stats
    end
end

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