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

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

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

1 comment

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

1 answer

✓ Accepted answer

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)

1 comment

0

thanks! And yes.. I know how to make a gui :)

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