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)
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)
“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”.
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)
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.
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)
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)