How to make it so that when you step on something a leaderstat goes up?

I am trying to make it so you step on a block and you go up a stage (lederstat) on my obby but I dont know the script for that at all. I looked it up on youtube and everything but I just have not manged to figure it out. It would be awesome if you could show me the script of how to do it and explain it to me so i dont run into the problem again and i also need explaining because I am new to Devolping.

Thank You so Much
-Madden21fan (why did i come up with this name) :smile:

1 Like

Maybe just add a script under the checkpoint and then add this:

script.Parent.Touched:Connect(function(hit)
hit.Parent.leaderstats.Level.Value = 0 -- change 0 to the stage number and also change Level to the leaderstat name
end)

i dont know any advanced way but this works might work

You can change the leaderstats value with the onTouched event.

script.Parent.Touched:Connect(function(hit)
 local plr = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent) -- gets the player
 if plr then -- checks if the player exists
   plr.leaderstats.statsname.Value = 1 -- change to the stage value
end
end)
1 Like

“Hit” returns whatever bodypart touches the part or if anything touches it. (doesn’t have to be a bodypart) It will return the character not the player so that won’t work. If I do print(hit), it will return something like “arm” or “torso”.

1 Like
local debounce = false
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if debounce == false
local player = game.Players:FindFirstChild(hit.Parent.Name)
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 10
debounce = true
wait(1)
debounce= false
end
end
end)
1 Like

Oh yeah I forgot about that. You would need debounce as well if you did it like that. You should actually just update the value instead of doing “+10” because he said it’s for an obby. So you wouldn’t need debounce.

1 Like

You put a lederstat in severscriptsevice correct?

1 Like

yes if you don’t know how to set up a leaderstats scripts dm me.

You can look here if you don’t know how to make leaderstats: In-Experience Leaderboards | Documentation - Roblox Creator Hub

none of these scripts work. Any other ideas?

Put this script inside the part. Edit: Updated the “stage” part to uppercase.

script.Parent.Touched:Connect(function(hit) -- onTouched event
  local plr = game.Players:GetPlayerFromCharacter(hit.Parent) -- literally gets the player like it says
   if plr then -- checks if the player exists. If not it will return nil
    plr.leaderstats.Stage.Value = 0 -- change this to the stage number
end)

Still does not work. I dont know why ps i made stage part upercase

Did you get any error in the console? If so can you show it to us? Edit: I’m dumb I forgot to add an end. Sorry.

script.Parent.Touched:Connect(function(hit) -- onTouched event
  local plr = game.Players:GetPlayerFromCharacter(hit.Parent) -- literally gets the player like it says
   if plr then -- checks if the player exists. If not it will return nil
    plr.leaderstats.Stage.Value = 0 -- change this to the stage number
       end
end)
2 Likes

Um i dont quite understand what that means. How do i check that?

Press “F9” if on laptop FN + F9.

Script still didnt work for me?

Again can you press F9 and show us what the console says if it says anything?

it does not do anything. The F9 thing.

If you’re on laptop press FN + F9

i am nothing is happening. I wont show anything?