Hi. I'm making an obby game and to do it I need to know how to get a player's leaderstats folder when they touch it. I've tried this but ultimately failed. Help will be greatly appreciated!
COMMUNITY QUESTION
How to get a player's leaderstats upon touching a part?
1 answer
It would be nice to have done some research before posting here, but anyways. Here is what to do:
insert a server script into a part
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then.
local players = game:GetService("Players")
local player = players:GetPlayerFromCharacter(hit.Parent)
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value +10 -- you can change this to whatever, but this would give the player ten cash if they have a value called "cash" in leaderstats
end
end)
Hope this has been fo help, if so, please accept as the answer :)
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
Btw, you can add debounce to it so it doesn't fire multiple times
You should also add a if statement to actually make sure it's a player.
oh yeah that too
if hit.Parent.Humanoid then is still going to error im pretty sure, it should use :FindFirstChild() instead