So i'm currently making a lift sim but i could not get the datastore working. I didn't find any errors in the code so i need help. Here is the code:
local ds = game:GetService("DataStoreService")
local StrengthData = ds:GetOrderedDataStore("Strength")
game.Players.PlayerAdded:Connect(function(player)
local getSavedStrength = StrengthData:GetAsync(player.UserId)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local strength = Instance.new("IntValue",leaderstats)
strength.Name = "Strength"
strength.Value = getSavedStrength
end)
game.Players.PlayerRemoving:Connect(function(player) -- i think the problem is in this function
local strengthValue = player.leaderstats.Strength
StrengthData:SetAsync(player.UserId,strengthValue)
print("saved data")
end)
When i was testing if the datastore works, it didnt even print "saved data" which is in the code. and btw the console doesnt print any errors
