Yeah, I fixed all four of them
This might be unrelated to the issue but the loading part of your script has a small issue. If a player has no data, it will print an error message. Do something like this instead:
local success, message = pcall(function()
Data = DataStore:GetAsync(Player.UserId)
end)
if success then
if Data then
Coins.Value = Data["Coins"]
Challenges.Value = Data["Challenges"]
--perform the rest of the script
else
print("Player has no data yet")
end
else
warn("Error with loading data. Error: "..message)
end
This is the part from your original script that I was talking about:
original script
if Data then
Coins.Value = Data["Coins"]
Challenges.Value = Data["Challenges"]
else
print("There Was An Error Saving"..Player.UserId)
end
It is saving correctly if this is what prints, you are most likely not changing the values of the leaderstats correctly. Is the script changing the values client sided?
This didn’t work either, unless I added it in completely wrong.
What about my previous reply with JSONEncode
? Also, you should still keep the script from my previous reply.
Everything is being changed in a normal Server script, if that is what you are asking.
Im trying it now, a bit confusing for me to put it in
As I was editing the script for you, I found the reason why your data wasn’t saving (or at least i think i did). You put the .PlayerRemoving
event inside of .PlayerAdded
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("CurrencyStats")
local HttpService = game:GetService("HttpService")
game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("Folder", Player)
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
local hiddenstats = Instance.new("Folder", Player)
hiddenstats.Name = "hiddenstats"
hiddenstats.Parent = Player
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Value = 0
Coins.Parent = leaderstats
local Challenges = Instance.new("IntValue")
Challenges.Name = "Challenges"
Challenges.Value = 0
Challenges.Parent = leaderstats
local success, message = pcall(function()
Data = DataStore:GetAsync(Player.UserId)
end)
if success then
print(Data)
if Data then
Coins.Value = Data["Coins"]
Challenges.Value = Data["Challenges"]
else
print("Player has no data")
end
else
warn(message)
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local success, message = pcall(function()
DataStore:SetAsync(Player.UserId, {
["Coins"] = Player.leaderstats.Coins.Value;
["Challenges"] = Player.leaderstats.Challenges.Value;
})
end)
if not success then
warn(message)
end
end)
If that doesn’t work, I’ll edit the script again with JSONEncode
and decode.
You can remove the HttpService variable I put on top since you probably don’t need it
Ahh! It worked!! Where in the script was the error btw? And thank you all for the help.
I didn’t test the script in studio, I just noticed it as I was trying to rewrite parts of the script for you.
lol i wonder how i didnt notice that either
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.