Giving leaderstats on touch used with instances

i made a part using an instance and now i want to give the player 10 coins when they touch it (Coins is a leaderstat) but it gives me the same error every time i run it
error
script

1 Like

You can’t get the player directly from the touched event. Try this:

newpart.Touched:Connect(function(hit)
     if hit.Parent:FindFirstChild("Humanoid") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        --changing player's coin value

Using GetPlayerFromCharacter can give you access to the player from it’s character in the workspace.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.