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)
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)
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
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.
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