I basically want to create a button "New Game" and when they press it their stats get reset. I have the gui and in the gui i have the Script That fires an event named "ResetData" but i dont know what to put in the server script that makes the remote event reset the stats
DataStore
local DataStoreService = game:GetService("DataStoreService")
local DataStoreVersion = 10 -- Changing this version will wipe all data of players
local DataStore = DataStoreService:GetDataStore("DataStorex"..DataStoreVersion) -- Changing "DataStoreV" will also wipe all data of players
game.Players.PlayerAdded:Connect(function(Player)
local Stats = Instance.new("Folder",Player)
Stats.Name = "Stats"
local Strength = Instance.new("IntValue",Stats)
Strength.Name = "Strength"
local Defense = Instance.new("IntValue",Stats)
Defense.Name = "Defense"
local Energy = Instance.new("IntValue",Stats)
Energy.Name = "Energy"
local Speed = Instance.new("IntValue",Stats)
Speed.Name = "Speed"
local Rebirths = Instance.new("IntValue",Stats)
Rebirths.Name = "Rebirths"
local loadedstrength
local loadeddefense
local loadedenergy
local loadedspeed
local loadedrebirths
local success,errormessage = pcall(function()
loadedstrength = DataStore:GetAsync(Player.UserId.."-Strength")
loadeddefense = DataStore:GetAsync(Player.UserId.."-Defense")
loadedrebirths = DataStore:GetAsync(Player.UserId.."-Energy")
loadedrebirths = DataStore:GetAsync(Player.UserId.."-Speed")
loadedrebirths = DataStore:GetAsync(Player.UserId.."-Rebirths")
end)
if success then
Strength.Value = loadedstrength
Defense.Value = loadeddefense
Energy.Value = loadedenergy
Speed.Value = loadedspeed
Rebirths.Value = loadedrebirths
else
print("Data load encountered an error,Player Data not loaded")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local success,errormesssage = pcall(function()
DataStore:SetAsync(Player.UserId.."-Strength",Player.Stats.Strength.Value)
DataStore:SetAsync(Player.UserId.."-Defense",Player.Stats.Defense.Value)
DataStore:SetAsync(Player.UserId.."-Energy",Player.Stats.Energy.Value)
DataStore:SetAsync(Player.UserId.."-Speed",Player.Stats.Speed.Value)
DataStore:SetAsync(Player.UserId.."-Rebirths",Player.Stats.Rebirths.Value)
end)
if success then
print("Data Save was successful")
else
print("Data Save Error Occured, Data not saved")
warn(errormesssage)
end
end)

3 comments
Maybe set all Values to 0 and then possibly save them
Can we get an example of the code used to save the data? This will help.
Ok, edited