Hi, I was trying to make an in-game settings and make it save so you don’t have to re-do it again. But it didn’t save at all.
Made a button inside PlayerGui, One is a No button and One is Yes.
Here the script for both of them.
--yes-button
local Storage = game:GetService("ReplicatedStorage")
local RE = Storage:FindFirstChild("ShadowsDisabled")
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
RE:FireServer(player)
end)
--no-button
local Storage = game:GetService("ReplicatedStorage")
local RE = Storage:FindFirstChild("ShadowsEnabled")
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
RE:FireServer(player)
end)
And this is the datastore script in SSS
local ds = game:GetService("DataStoreService"):GetDataStore("Test")
local Sere = game.ReplicatedStorage.ShadowsEnabled
local sere = game.ReplicatedStorage.ShadowsDisabled
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder", plr)
folder.Name = "TestA"
local val = Instance.new("IntValue", folder)
val.Name = "ShadowsEnabled"
local stats = ds:GetAsync(plr)
if stats ~= nil then
val.Value = stats[1]
else
val.Value = 1
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local save = { }
table.insert(save, plr.TestA.ShadowsEnabled.Value)
ds:UpdateAsync(plr.UserId, save)
end)
Sere.OnServerEvent:Connect(function(plr)
plr.TestA.ShadowsEnabled.Value = 1
end)
sere.OnServerEvent:Connect(function(plr)
plr.TestA.ShadowsEnabled.Value = 0
end)
I didn’t test the data inside of the studio but did it on Roblox.
Use “tostring()” on the key. Strings are used as keys in SetAsync and GetAsync (as well as UpdateAsync and IncrementAsync, and so on). The value, on the other hand, can be any type of Variant.
local ds = game:GetService("DataStoreService"):GetDataStore("Test")
local Sere = game.ReplicatedStorage.ShadowsEnabled
local sere = game.ReplicatedStorage.ShadowsDisabled
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder", plr)
folder.Name = "TestA"
local val = Instance.new("IntValue", folder)
val.Name = "ShadowsEnabled"
local stats = ds:GetAsync(tostring(Player.UserId))
if stats ~= nil then
val.Value = stats[1]
else
val.Value = 1
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local save = { }
table.insert(save, plr.TestA.ShadowsEnabled.Value)
ds:UpdateAsync(plr.UserId, save)
end)
Sere.OnServerEvent:Connect(function(plr)
plr.TestA.ShadowsEnabled.Value = 1
end)
sere.OnServerEvent:Connect(function(plr)
plr.TestA.ShadowsEnabled.Value = 0
end)
Upon checking the code with a mate, the code seems fine, you just need to make sure you publish and test it in the actual game. DS doesn’t work when testing in Studio.