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

Why are my Data Stores only saving with the use of changing the value through the console?

Asked by 5 years ago

I’ve been working on a game and Data Storing has been a problem with me for a while. It might be some setting I haven’t enabled: Something so my scripts change a value then have that same changed value be saved by my Data Store. or it could also just be the Data Store script itself. The weirdest thing is that if I go into a game and use the developer console, to change the value, it saves it.

Script:
local DataStoreService = game:GetService(“DataStoreService”)

local myDataStore1 = DataStoreService:GetDataStore(“myDataStore1”)

game.Players.PlayerAdded:Connect(function(player)

local Stats = Instance.new(“Folder”)

Stats.Name = “Stats”

Stats.Parent = player

local cash = Instance.new(“IntValue”)

cash.Name = “Cash”

cash.Parent = Stats

local data

local success, errormessage = pcall(function()

data = myDataStore1:GetAsync(player.UserId…"-cash")

end)

if success then

cash.Value = data

print(“Player Data successfully loaded!”)

else

print(“There was an error whilst getting your data”)

warn(errormessage)

end

end)

game.Players.PlayerRemoving:Connect(function(player)

local success, errormessage = pcall(function()

myDataStore1:SetAsync(player.UserId…"-cash",player.Stats.Cash.Value)

end)

if success then

print(“Player Data successfully saved!”)

else

print(“There was an error when saving data”)

warn(errormessage)

end

end)

Hopefully you guys can help me! Thanks.

0
You did not format your code properly. Please do so. Also I am pretty sure that your datastore is not the problem. Are you trying to edit values from the client? If so that is the issue. valchip 789 — 5y
0
Thank you so much! The problem was, the script I was making change the value was a local script instead of a normal script! Rookie mistake. nickos3 4 — 5y

Answer this question