✓ Accepted answer
I assume you are using a Server Script. LocalPlayer is for LOCAL SCRIPTS ONLY!!! So, if you want to find out who the player is, then you need to do it in another way. Think of it: If someone else that is not you steps on the giver, then you'll still earn the points! Also, the character in Workspace is a model, and the Touched event only returns the part that touched (triggered) it. So, you need to refer to its parent in order to get the player.
Apart from that, in line 5, you are trying to change the leaderstats the wrong way. Let me help you fix it.
Here is the script:
local giver = script.Parent
local db = false
local function SteppedOn(part)
if not db then
db = true
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player then
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 10
end
wait(1)
db = false
end
end
giver.Touched:connect(SteppedOn)
Any questions? Leave them in the comments below! Thanks! :)
3 comments
Just a suggestion, adding a Debounce, otherwise the function will be run multiple times on touch.
updated!
Thanks so much! I will look into learning more about debounce.