How do i clear a datastore for a certain player using a script
It depends on how you save data to your DataStore. Do you happen to know how the data is saved for each player, and what the DataStore is called?
If not, could you provide the code(s) that saves data via DataStore in your game.
To completely wipe a given user’s data, use the dataStore:RemoveAsync(key)
method.
ok here
local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“Stage”)
local RPS = game:GetService(“ReplicatedStorage”)
local DeathEvent = RPS.Events.DeathEventgame.Players.PlayerAdded:Connect(function(player)
local data
local success, errorMessage = pcall(function()
data = myDataStore:GetAsync(player.UserId)
end)if success then
player.leaderstats.Stage.Value = data
else
warn(errorMessage)
end
end)game.Players.PlayerRemoving:Connect(function(player)
local data
local success, errorMessage = pcall(function()
data = myDataStore:SetAsync(player.UserId, player.leaderstats.Stage.Value)
end)if success then
print(“Data Saved”)
else
warn(errorMessage)
end
end)game:BindToClose(function()
for i, v in pairs(game.Players:GetChildren()) do
v:Kick(“Server Closed”)
endwait(2)
end)
give a code example please it would really help
If you have the player’s ID, say it is 123, this is what you can execute into studio’s command bar to remove their data.
local id = 123
game:GetService("DataStoreService"):GetDataStore("Stage"):RemoveAsync(id)
I’m making the game whereas when player dies their stats are reset back to zero as in like the checkpoints so I’m wondering how would you go about doing this yes i have tried using remote events
In that case, I wouldn’t use the DataStore everytime a player dies. Instead, I would just update the value as necessary then keep the DataStore as is, which is setting the data when the player leaves the game rather than multiple times during the game.
Here is what you can do, in a new script.
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(body)
body:WaitForChild("Humanoid").Died:Connect(function()
player:WaitForChild("leaderstats"):WaitForChild("Stage").Value = 0
end)
end)
end)
Server Script or local? and also the way i was doing it kept spawning me on the wrong checkpoint can i have your Discord to use instead of the forum
You would do that in a server script. If you’d like to contact me on discord, my username is Vinny#8495