How do i put my int values into a table and save them in DataStore

So I have script that updates game settings when those values changes, but my saves doesn’t work :frowning:

I’ve tried a lot of methods and nothing actually helped, there is no warning, no errors, just nothing, even prints not appearing

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local DataStoreService = game:GetService("DataStoreService")
local SettingsDS = DataStoreService:GetDataStore("Settings")

game.Players.PlayerAdded:Connect(function(player: Player) 
	task.wait(10)
	local data
	local success, err = pcall(function()

		data = SettingsDS:GetAsync(player.UserId)

	end)

	if success and data then
		
		print(data)
		
	else
		warn(err)
	end
end)

game.Players.PlayerRemoving:Connect(function(player: Player, reason: Enum.PlayerExitReason) 
	local data = {
		LowPerformance = player.PlayerGui.Settings.LowPerformance.Value,
		MusicVolume = player.PlayerGui.Settings.MusicVolume.Value,
		Walkspeed = player.PlayerGui.Settings.WalkSpeed.Value,
		Trades = player.PlayerGui.Settings.Trades.Value
	}
	local success, err = pcall(function()
		SettingsDS:SetAsync(player.UserId, data)
	end)
	
	if success then
		print("successed")
	end
end)
1 Like

and yeah here is my update script, its pretty bad but I don’t have any strength to make something smarted anymore

local player = game.Players.LocalPlayer
local UIService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local Settings_GUI = player.PlayerGui:WaitForChild("Settings")
local Low_Performance = Settings_GUI.LowPerformance
local Music_Volume = Settings_GUI.MusicVolume
local WalkSpeed = Settings_GUI.WalkSpeed
local Trades = Settings_GUI.Trades

Low_Performance.Changed:Connect(function(value: boolean) 
	if Low_Performance.Value == true then
		game.Lighting.GlobalShadows = false
		game.Lighting.EnvironmentSpecularScale = 0
		game.Lighting.EnvironmentDiffuseScale = 0
	else
		game.Lighting.GlobalShadows = true
		game.Lighting.EnvironmentSpecularScale = 1
		game.Lighting.EnvironmentDiffuseScale = 1
	end
end)

Music_Volume.Changed:Connect(function(value: number) 
	game.SoundService.Sound.Volume = math.round(Music_Volume.Value)
end)

1 Like

What sort of script is updating the values of the different settings? Is it a local script or a Server script?

Local, i think Im starting to understand what i did wrong

Hey!

You actually just discovered the issue! Changing those values on the client (local-script) does not mean it is replicated to the server. The data is saved on the server and is the only way of saving your data.

Server automatically replicates to the client, but the client does not replicate to the server. This is intended and it is important it works like this.

So the fix is to make sure you changes those values on the server, using regular scripts! After that, the data should be correctly saved!

Sincerely,
ModzZealous

1 Like

Use ProfileStore if you are not used to handling DataStore; it’s easier and safer.

thank you so much! Yeah i guess night coding is a bad thing

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.