I think the title explains it all. Here is my code:
local dss = game:GetService("DataStoreService")
local datastore = dss:GetDataStore("PurchaseCarDataStore")
local intvalue = game.ReplicatedStorage.Purchasedbmw
game.Players.PlayerAdded:Connect(function(player)
local playergui = player:WaitForChild("PlayerGui")
local purchasegui = playergui:WaitForChild("PurchaseGUI")
local frame = purchasegui:WaitForChild("Frame")
local bmw = frame:WaitForChild("bmw")
local textbutton = bmw:WaitForChild("TextButton")
local folder = Instance.new("Folder",player)
folder.Name = "leaderstats"
local cash = Instance.new("IntValue",folder)
cash.Name = "Cash"
local savedData = nil
local ID = intvalue.Name.."-"..player.UserId
print(ID)
pcall(function()
savedData = datastore:GetAsync(ID)
end)
if savedData ~= nil then
intvalue.Value = savedData
print("Data loaded! - "..intvalue.Value)
else
intvalue.Value = 0
print("New player to the game, value is false - "..intvalue.Value)
end
if intvalue.Value == 1 then
textbutton.Text = "Spawn"
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local ID = intvalue.Name.."-"..player.UserId
datastore:SetAsync(ID,intvalue.Value)
end)
game:BindToClose(function()
for i,player in pairs(game.Players:GetPlayers()) do
if player then
player:Kick()
end
end
end)
The problem is, when I first join the game everything works fine, but when I rejoin it says that data was loaded, however, before leaving the game and rejoining I changed the value to 1, and when I rejoin it says "Data loaded - 0" (it's supposed to say 1 instead of the 0). Also, the text doesn't change to "Spawn". Any fixes?

2 comments
How did you change the value? Because if you know the difference between client and server, you'll know that client changes are not seen by the server, make sure the value is changed on the server and not the client
I changed it using a local script, so yeah, I changed it using client, and not with the server. I'll try changing it with the server.