This data store script doesn't work for some reason. Can you guys check it out please. I have put print() after if nil then and it did not print, this means that the data store is saving but it's not saving the right value.
Script location = ServerScriptService
local xp = game:GetService("DataStoreService"):GetDataStore("XP")
local function Xp(key, newValue)
local suc, res = pcall(function() return xp:SetAsync(key, newValue) end)
if suc then
return true
end
end
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local experience = Instance.new('IntValue')
experience.Name = 'XP'
experience.Value = xp:GetAsync(player.UserId)
if nil then
-- I put the print() in here
experience.Value = 0
end
while wait(30) do
Xp(player.UserId, player.XP.Value)
end
end)
end)

11 comments
I actually do need player.CharacterAdded, because i have other data stores i just took one of them out of my script
Create a new script and datastore key to store the other value.
if you want me try to fix, send all code. with another data store
I disabled my Data Store script and pasted yours in a new script, it didn't work
what error? (remember if you using "XP" data store on two scripts, you need to change the key in one of the two)
Remember, only can save the values if server change. if the client change not save anything, for this use Remote Event or Server Script.
No Error
If no error you need to change the value with server, For this use RemoteEvent or Server Script.
Done that didn't work
I do not know then, because I tried the script and it works perfectly for me. (If you already used the DataStore "XP" change for "XP-0" or anything number...)
I figured it out It was that i wasn't changing the value on the server side but i thought i did, but i guess not (btw i tested with my original code and it works perfectly)