My datastore script won't work?
I have API services enabled aswell
This is the script
local ds = game:GetService("DataStoreService"):GetDataStore("UserData")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder", plr)
leaderstats.Name = "leaderstats"
local Swing = Instance.new("IntValue", leaderstats)
Swing.Name = "Swing"
local Coins = Instance.new("IntValue", leaderstats)
Coins.Name = "Coins"
local Rebirths = Instance.new("IntValue", leaderstats)
Rebirths.Name = "Rebirths"
local key = "plr-".. plr.userId
local SavedData = ds:GetAsync(key)
if SavedData then
Swing.Value = SavedData[1]
Rebirths.Value = SavedData[2]
Coins.Value = SavedData[3]
else
local DataToSave = {Swing.Value, Rebirths.Value, Coins.Value}
ds:SetAsync(key, DataToSave)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local key = "plr-".. plr.userId
local DataToSave = {plr.leaderstats.Swing.Value, plr.leaderstats.Rebirths.Value, plr.leaderstats.Coins.Value}
ds:SetAsync(key, DataToSave)
end)
