How do I make a reset progress button that actually works?

I’m currently working on an obby game, and it has a save system, however, I’m trying to make a reset progress button, and I don’t know where to start. I originally tried to make it kill the player and reset the value to 1 so they spawn on stage 1. When I did that though, it said they were on stage 1, but they were on the stage that they were originally at. What would be a way to make a reset progress/stage button?

local button = script.Parent

button.MouseButton1Click:Connect(function()
    local clicked = game.Players.LocalPlayer
    print(clicked)
    clicked.leaderstats.Stage.Value = 1
    clicked.leaderstats.Attempts.Value = 0
    clicked.Character.Humanoid.Health = 0
    game.ReplicatedStorage.ResetState.Value = true
end)
1 Like

This really depends on how and where your data is stored, and how you load the player with that data. Could you provide a little more information on that?

and we need to know where you are changing that value back to 1 cause if it is in the client then it will not update as it should where as EXAMPLE

SERVER: Value = 10
CLIENT: Value = 1

the server will save 10 and put you to 10 do you understand what im trying to say??

Alright I edited the post to show the script.

Ok, it looks like you’re setting it locally, you need to make sure you’re setting the Stage value on a server script. You can do this by firing a remote, and then using the OnServerEvent function. The value will only properly update when its done server side.

3 Likes

But how am I going to do that if it’s a local script in a GUI?

Just place a remote event in ReplicatedStorage, name it “ResetStage”, on your local script, put

game.ReplicatedStorage.ResetStage:FireServer(clicked)

Then, create a script, place it into ServerScriptService, and add the following:

game.ReplicatedStorage.ResetStage.OnServerEvent:Connect(function(clicked)
    clicked.leaderstats.Stage.Value = 1
    clicked.leaderstats.Attempts.Value = 0 
    clicked.Character.Humanoid.Health = 0
end)
10 Likes

It works, thank you very much for the help!

Anytime, glad I could help you!

1 Like