Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Data Store is not working as attended? [Solved]

Asked by 1 month ago
Edited 1 month ago

Hi, so I have a strength leaderstat which should save when I leave the game. However, it does not do that. I have turned API Services on and have a bool value in server storage named SaveInStudio and the value is true. Can anyone help please?

Script:

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("StrengthSaveSystem")

game.Players.PlayerAdded:connect(function(player)
    local leader = Instance.new("Folder",player)
    leader.Name = "leaderstats"
 local Strength = Instance.new("IntValue",leader)
 Strength.Name = "Strength"
 Strength.Value = ds:GetAsync(player.UserId) or 0
 ds:SetAsync(player.UserId, Strength.Value)
 Strength.Changed:connect(function()
  ds:SetAsync(player.UserId, Strength.Value)
 end)
end)


game.Players.PlayerRemoving:connect(function(player)
 ds:SetAsync(player.UserId, player.leaderstats.Strength.Value)
end)

1 answer

Log in to vote
0
Answered by 1 month ago

I have figured it out. It was because I was adding values from a local script when it should be from the server side. My mistake. The script works perfectly fine.

Ad

Answer this question