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

How to get a player's leaderstats upon touching a part?

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!

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 :)

4 comments

0

Btw, you can add debounce to it so it doesn't fire multiple times

0

You should also add a if statement to actually make sure it's a player.

0

oh yeah that too

0

if hit.Parent.Humanoid then is still going to error im pretty sure, it should use :FindFirstChild() instead

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