I don’t think you can erase all data from a DataStore.
I’m sorry if I Sound stupid, but where do I put this script?
Ok, a few things because I don’t want to restate what others have said but you did say you were a beginner
- Use playerid, not player name as if the player changes their name they will lose their data
- As @janpieterkes said, you need to include a line that copies the players data over IF they had data from their username, or a “redundacy line”. This would look something like this:
local success, erorrMessage = pcall(function() --Wrap in a pcall incase error (no data associated with the username)
local olddata = Datastore:GetAsync(player.Name) --Get old data, replace the Datastore with your name
Datastore:SetAsync(player.UserId) --Set the old data to the players new table
end)
if not success then
warn(errorMessage) --Will print the error to console, if you dont want this just do task.wait()
end
This should fix it, but I definitley reccomend learning a bit more in terms of basic coding before attempting an advanced topic like datastores. Keep in mind that you will still have to tell the Datastore what to save and load.
If it were to go there, how many peoples data would be lost? Just wondering
You can erase all Data from the DataStores, all that would be left however are the Keys.
around 2600-2700 players have data
Hm, okay. Have you tried doing it manually with a plugin called BloxBiz?
Also, try this and tell me if it works
Also, why did you use Player.Name
, The Players Name is not permanent. And the Players UserId is, if you have a Key for a Player, that is under their name. And they decide to change their bame, the Data would be lost because you are trying to Access another Key.
Where do I Put this script,
in the Data script, ServerScriptService or something else?
DataToTransfer = DataStore1:GetAsync(Key) --if you are saving by UserId, Key would be the user you want to work with's UserId
DataStore2 = DataStore2:SetAsync(Key, DataToTransfer) --Set the value of the second DataStore to the value of the first
You would put this in the datastore script. And change first Key to the players name, second key to players userid. Wrap it in a pcall function like I did before
Also, I have to ask, if you are a beginner scripter why are you scripting for a game with 2000+ players?
I’m not the scripter there, We don’t have enough to pay for scripters so we’re using scripts we are seeing on youtube/dev forum
Oh, okay. Obviously in the future I reccomend writing your own scripts. As for right now, do some research on data stores and look for solutions.
That’s what it’s saying, How do I fix it?
That’s what I did right now:
--[[Savin'
Dem
Stats
--]]
game.Players.PlayerRemoving:connect(function(player)
local datastore = game:GetService("DataStoreService"):GetDataStore(player.UserId.."Stats")
local statstorage = player:FindFirstChild("leaderstats"):GetChildren()
for i = 1, #statstorage do
datastore:SetAsync(statstorage[i].Name, statstorage[i].Value)
print("saved data number "..i)
end
print("Stats successfully saved")
end)
--[[
Loadin'
Dem
Stats
--]]
game.Players.PlayerAdded:connect(function(player)
local datastore = game:GetService("DataStoreService"):GetDataStore(player.UserId.."Stats")
player:WaitForChild("leaderstats")
wait(1)
local stats = player:FindFirstChild("leaderstats"):GetChildren()
for i = 1, #stats do
stats[i].Value = datastore:GetAsync(stats[i].Name)
print("stat numba "..i.." has been found")
end
end)
DataToTransfer = DataStore1:GetAsync(player.Name) --if you are saving by UserId, Key would be the user you want to work with's UserId
DataStore2 = DataStore2:SetAsync(player.UserId, DataToTransfer) --Set the value of the second DataStore to the value of the first
You didnt change the data store names in the code I gave you…
If this isn’t resolved In about 3 hours I’ll be able to help you on my pc
Please do not ask for code, as it is against the rules.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.