Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Making a restart button for my game that resets all data.. how?

Asked by 5 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

So, I'm making a simulator game and wondering how to make a restart button (GUI) that resets all the player's leaderstats data (data being points and prestige) Hope I can get some help on this :)

0
this is not a script request site but i can tell u this, when u press the button then u need to fire an event to a server script that can put all the data back to 0 Gameplayer365247v2 1055 — 5y

1 answer

Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago

I am assuming here you are capable of making a GUI Button. The solution to this is straight forward, just set the DataStore data for the player to the default data when the player clicks the button. Since the GUI button would be client-side, you would need to send a remote signal to the server to do the data clearing.

For example, your scripts may look something like this:

-- local script
local guiButton = reference.to.gui.button
local remoteEvent = reference.to.remote.event

guiButton.Activated:Connect(function(inputObject)
    remoteEvent:FireServer()
end)

-- server script
local datastore = game:GetService('DataStoreService')
local store_playerData = datastore:GetDataStore('playerData')
local defaultData = {
    -- Set the default data
    Money = 0,
    Stats = 0,
    Level = 0,
}

remoteEvent.OnServerEvent:Connect(function(player)
    -- Get access to the player's datastore 
    local playerKey =  "Player_"  .. player.UserId
    local success, err =  pcall(function()
        store_playerData:SetAsync(playerKey,  defaultData)
    end)

    if not success then print(err) end
end)
0
thanks! And yes.. I know how to make a gui :) hotpot888 2 — 5y
Ad

Answer this question