Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Data Store is not working as attended? [Solved]

Asked by 3 years ago
Edited 3 years 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 3 years 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