My ingame Settings is Not Saving

Hello there,

I have two Issues Where my InGame Settings Wont Save I think my Script is Where it Changes the Number Is not Changing I thought it might Be I have It In a LocalScript. My Second Issue is the Saving Script I keep Getting errors.

Script 1

local Rep = game:GetService("ReplicatedStorage").BoolVal
local Event1 = Rep:WaitForChild("BoolValue1")
local Event2 = Rep:WaitForChild("BoolValue2")
local Event3 = Rep:WaitForChild("BoolValue3")
local Value1 = script.Parent.Value1
local Value2 = script.Parent.Value2
local Value3 = script.Parent.Value3
Value1.Parent = workspace
Value2.Parent = workspace
Value3.Parent = workspace



local function onValueChanged()
Value1.Value = 1
Value2.Value = 0
Value3.Value = 0
end

Event1.OnClientEvent:Connect(onValueChanged)
Value1.Changed:Connect(onValueChanged)


local function onValueChanged1()
	Value1.Value = 0
	Value2.Value = 1
	Value3.Value = 0
end

Event2.OnClientEvent:Connect(onValueChanged1)
Value2.Changed:Connect(onValueChanged1)


local function onValueChanged2()
	Value1.Value = 0
	Value2.Value = 0
	Value3.Value = 1
end

Event3.OnClientEvent:Connect(onValueChanged2)
Value3.Changed:Connect(onValueChanged2)

Second Script


local BoolValue1 = script.Parent.SettingsValues.Value1
local BoolValue2 = script.Parent.SettingsValues.Value2
local BoolValue3 = script.Parent.SettingsValues.Value3

local dataStore = game:GetService("DataStoreService"):GetDataStore("SettingsData")

game.Players.PlayerAdded:Connect(function(plr)
	wait()
	local plrid = "id_"..plr.UserId
	local save1 = BoolValue1
	local save2 = BoolValue2
	local save3 = BoolValue3

	local GetSaved = dataStore:GetAsync(plrid)
	if GetSaved then
		save1.Value = GetSaved[1]
		save2.Value = GetSaved[2]
		save3.Value = GetSaved[3]
	else
		local NumberForSaving = {save1.Value, save2.Value, save3.Value}
		dataStore:GetAsync(plrid,NumberForSaving)
		print(plr.Name.."'s Settings Are Getting Updated in our Datastore!")
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
if BoolValue1.Value == 0 or BoolValue1.Value == 1 then
dataStore:SetAsync("id_"..plr.UserId, BoolValue1.Value)
	elseif BoolValue2.Value == 0 or BoolValue2.Value == 1 then
		dataStore:SetAsync("id_"..plr.UserId, BoolValue2.Value)
	elseif BoolValue3.Value == 0 or BoolValue3.Value == 1 then
		dataStore:SetAsync("id_"..plr.UserId, BoolValue3.Value)

end
end)

Error

If Some One Can Show Me Where It’s going Wrong in the Script that Would be Great!

Official_SimuIation

Btw The BoolValues are IntValues if you were Asking

Well, a possible issue to why your data wont save is because, by the looks of it, youre changing the values through the client.

This will cause the server to still see the default settings, because client changes do not replicate to the server.

You’ll have to change the values through the server, with a remote event.

And for the error you attached, it seems that is happening because your data is not a table, and data[1] does not exist.

Using :SetAsync will update the datastore to only have the value that you put in.
So what this script is doing is this:

If value 1 exists then
update datastore to value 1, Remove value 3

If value 2 exists then
update datastore to value 2, Remove value 1

If value 3 exists then
update datastore to value 3, Remove value 2

To fix this, just use tables.

DataToSave = {
["Value1"] = value1.value;
["Value2"] = value2.value;
["Value3"] = value3.value;
}
dataStore:SetAsync("id_"..plr.UserId, DataToSave)
1 Like

The Changes made by local script are almost never replicated to server. Say you are changing a parts color to blue while it was red. You will be seeing it blue but the server still sees it red. Why? The change wasnt replicated to server.

Same happens here.your values change locally and dont replicate to server.this is why we use remoteevents/remotefunctions.

Before i tell what causes the 2nd issue i want to ask why are u using IntValues here as 1s and 0s. You should use boolvalues for that instead. Its easier.

The second issue is caused because you are only saving 1 value not a table.

You are tryna do 1[1]. Does that make sense?

So the solution is pretty simple here,
1st Issues Resolution : use remotes to do the same thing on server
2nd Issues Resolution : Change you code for player removing to -

game.Players.PlayerRemoving:Connect(function(plr)
local TableToSave = {BoolValue1.Value,BoolValue2.Value,BoolValue3.Value}
datastore:SetAsync("id_"..plr.UserId,TableToSave)
end)

I’ll Go Try to see If They fix the issue.

For me to Make a Script and have RemoteEvents what Would be the Best Way to Do It? If there is No other Way I Can Just try To Somehow Make it Where Only a local Player Can See it

image

Well, by the looks of it, youre just using 3 different remote events to change the values, so in the code where the server fires them to the client, just update the values through the server side before firing to the client.

I would however, recommend using a single remote event, and just firing a table over with the 3 values in it, to make the game neater.

Okay So I Don’t need to use Remote Events are you Saying?

If the settings gets updated through a UI element, you will have to use remote events.

However, if youre using something like a proximity prompt, or click detector (for whatever reason) you will not have to use remote events.

As long as the server knows when it has to update the values, you should be good.

1 Like

I’ll Go And Fix Things And I’ll Be Back To See If I Fixed the issue

what I Have Done is For the SettingsSaver Script is this But I’m Still Getting the error

And For the Other One I have Made It in another Script


if I have Done it Wrong I’m Sorry.

I Tried BoolValues But I couldn’t get it to Work and I’m not the best Scripter out there

datastore:getasync is returning a number instead of a table, you probably have prior data saved that can’t be properly overwrote because PlayerRemoving does not fire when the last player leaves the server

Ima Try BoolValue Again and See if I Can Get It work :crossed_fingers:

I Couldn’t find the Issue but Thank you for the Help everyone I’ll See if I can Fix it

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