temporalData[plr.UserId] = ds:GetAsync(plr.UserId) or {}
Still, not working. Is the table saving a seperate value or is it saving the leaderstats value?
I think you’re changing Wins instead of Coins
And what do you mean by that??
doesnt work for wins either coins.
This should work:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local isStudio = RunService:IsStudio()
local DataStoreService = game:GetService("DataStoreService")
local ds = DataStoreService:GetDataStore("LeaderStatSave")
local temporalData = {}
Players.PlayerAdded:Connect(function(plr)
local leader = Instance.new("Folder")
leader.Name = "leaderstats"
local Coins = Instance.new("NumberValue", leader)
Coins.Name = "Coins"
local Wins = Instance.new("NumberValue", leader)
Wins.Name = "Wins"
leader.Parent = plr
temporalData[plr.UserId] = ds:GetAsync(plr.UserId) or {}
Coins.Value = temporalData[plr.UserId].Coins or 0
Coins:GetPropertyChangedSignal("Value"):Connect(function()
temporalData[plr.UserId].Coins = Coins.Value
end)
Wins.Value = temporalData[plr.UserId].Wins or 0
Wins:GetPropertyChangedSignal("Value"):Connect(function()
temporalData[plr.UserId].Wins = Wins.Value
end)
plr.AncestryChanged:Connect(function()
if plr:IsDescendantOf(game) or temporalData[plr.UserId] == nil then
return
end
if isStudio then
print("Data not saved because it runs in Studio")
return
end
local s, err = pcall(function()
ds:UpdateAsync(plr.UserId, function()
return temporalData[plr.UserId]
end)
end)
if s ~= true then
warn("Failed saving data for player: " .. plr.Name .. ", key: " .. plr.UserId .. "\n" .. tostring(err))
else
print("Data saved for player: " .. plr.Name)
end
temporalData[plr.UserId] = nil
end)
end)
That is because there is a error i found.
“ServerScriptService.Leaderstats.TP:Data:21: attempt to index number with ‘Coins’”
This line is breaking it.
Coins.Value = temporalData[plr.UserId].Coins or 0
Update: it works but only outside of studio
What about the error though? It shows on my studio
Erm, it doesn’t work outside of roblox either.
Shows the error
ServerScriptService.Leaderstats.TP:Data:21: attempt to index number with 'Coins'
EDIT: Added .Value, still not working.
It does, look at 46th post, try changing your data with developer console:
game.Players.masterminyxs.leaderstats.Coins.Value = 123
Leave and rejoin
Still doesn’t work. This is actaully really odd
Still gives me the error.
Ugh just replace your entire code with the one I sent at post 46, it works
I did! I don’t know whats doing it.
I keep getting a error on the code about
ServerScriptService.Leaderstats.TP:Data:23: attempt to index number with ‘Coins’
Looking at your code, there is no reason it shouldn’t work. However, I’d recommend you look at other similar issues posted on here before looking at yours. Try implementing the game:BindToClose
function.
In your case, the code would be something along the lines of this:
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
ds:SetAsync(player.UserId, player.Abilities.Boost.Value)
ds2:SetAsync(player.UserId, player.Abilities.Heal.Value)
ds3:SetAsync(player.UserId, player.Abilities.Engineer.Value)
end
end)
Edit: It appears as if you’ve changed your code completely, but you could try this with the original code to see if it would still work.
Uh, it broke my ability datastore.
By the way, the code you sent me does not save because it can’t get to the part where it saves because of this weird code.
It shouldn’t break anything, what is your current code?