I’m trying to make a script that erases someone’s data in the data store (Set it to 0), I got the data store plugin but I want to challenge myself. I have a script that doesn’t erase someone’s data but sets it to 1, everyone has the same key so it’s more challenging.
local players = game:GetService("Players")
local Exploiters = {"stickymirro511","player"}
local DataStoreService = game:GetService("DataStoreService")
local pointDataStore = DataStoreService:GetDataStore("PointDataStore")
for i,v in next, Exploiters do
local exploiterUserId = players:GetUserIdFromNameAsync(v)
pointDataStore:SetAsync(exploiterUserId, 1)
end
I tried using that script but it wouldn’t erase my data, if I set it to 1 it changes my data to that. I assume
SetAsync only works when you have to set a player’s data to anything higher than 0. If you could help me out, please do, thanks.
To “erase” data, you don’t set its value to 0 or 1. You should use the “RemoveAsync” method on the players’ keys (pointDataStore:RemoveAsync(Key)). See if that accomplishes what you are trying to achieve.
1 Like
Thanks for the help, but like I said in the post, everyone uses the same key. Is there a way to erase only one person’s data? Using the same concept as my script in the post?
local players = game:GetService("Players")
local Exploiters = {"stickymirro511","player"}
local DataStoreService = game:GetService("DataStoreService")
local pointDataStore = DataStoreService:GetDataStore("PointDataStore")
for i,v in next, Exploiters do
local exploiterUserId = players:GetUserIdFromNameAsync(v)
---Erase Player's Data
end
How does everyone use the same key? Can you provide me below with what your data store looks like? (so if I were to do :GetAsync() on the one key that you have for all players, show me what it would return)
This is the script that holds my data store.
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("TimeSave") ---Data Store
local badgeservice = game:GetService("BadgeService")
local badgeid = 2124568187
local badgeid2 = 2124568189
local badgeid3 = 2124568190
local badgeid4 = 2124568192
game.Players.PlayerAdded:Connect(function(plr)
local m = 0
local leaderstats = Instance.new("Folder")
leaderstats.Parent = plr
leaderstats.Name = "leaderstats"
local gems = Instance.new("IntValue")
gems.Parent = leaderstats
gems.Name = "Time"
local data
local success, err = pcall(function()
data = ds1:GetAsync(plr.UserId)
end)
if success then
gems.Value = data
end
repeat wait()
m = m + 1
if m == 2 then
m = 0
if plr.leaderstats.Time.Value >= 600 then
badgeservice:AwardBadge(plr.UserId, badgeid)
if plr.leaderstats.Time.Value >= 1800 then
badgeservice:AwardBadge(plr.UserId, badgeid2)
if plr.leaderstats.Time.Value >= 3600 then
badgeservice:AwardBadge(plr.UserId, badgeid3)
if plr.leaderstats.Time.Value >= 7200 then
badgeservice:AwardBadge(plr.UserId, badgeid4)
end
end
end
end
end
wait(1)
plr.leaderstats.Time.Value = plr.leaderstats.Time.Value + 1
until plr == nil
end)
Should i use the userid as the key, as if I were using the data store plugin?
You seem to be using different keys for every player-- the key is the UserID of each player according to this script, which is of course different for every different player. So, if you want to remove the data from userID 54556995, for example, just do ds1:RemoveAsync(54556995).
If I want to do it in a whole different script how would i do that? Something like this?
local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("TimeSave") ---Data Store
local Exploiters = {"player","player"}
for i,v in next, Exploiters do
local exploiterUserId = players:GetUserIdFromNameAsync(v)
ds1:RemoveAsync(exploiterUserId)
end
Yup, that’ll work. Try it out.
1 Like