Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Find the player who have touch the part ?

Asked by 5 years ago

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

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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
Ad

Answer this question