Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Data Store is not working as attended? [Solved]

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

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.