-
What do you want to achieve? Keep it simple and clear!
So basically, I want to save the gui settings for each player, including the values and the look on the gui (which I will implement later).
-
What is the issue? Include screenshots / videos if possible!
The issue is that the data doesn’t seem to be received or stored when the player joins or tries to save. And if it does somehow work, it would import the wrong data.
Video with 2 local players:
Picture of Explorer:
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried numerous ways. I’ve looked at this topic, but I couldn’t get anything working.
LocalScript:
wait(3)
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local SettingsGUI = Players.LocalPlayer.PlayerGui.SettingsGUI
local TogglesFolder = SettingsGUI.Popup.List1.Toggles
local ValuesFolder = SettingsGUI.Popup.List1.Values
local SettingsValuesFolder = ReplicatedStorage.SettingsValues
local RemoteEventsFolder = ReplicatedStorage.Remotes
--listing buttons
local EnableShoulderCameraButton = TogglesFolder.EnableShoulderCamera
local NoParticlesButton = TogglesFolder.NoParticles
local PerformanceModeButton = TogglesFolder.PerformanceMode
local SaveButton = SettingsGUI.Popup.Save
--listing values of buttons
local EnableShoulderCameraValueButton = ValuesFolder.EnableShoulderCameraValue
local NoParticlesValueButton = ValuesFolder.NoParticlesValue
local PerformanceModeValueButton = ValuesFolder.PerformanceModeValue
--listing values in folders non-button
local EnableShoulderCameraValue = SettingsValuesFolder.ShoulderCameraOnly
local NoParticlesValue = SettingsValuesFolder.NoParticles
local PerformanceModeValue = SettingsValuesFolder.PerformanceMode
--listing Remotes
local SaveSettingsEvent = ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("SaveSettingsEvent")
--code events
local function ShoulderCameraValueToggled()
if EnableShoulderCameraValueButton.Text == "Enabled" then
EnableShoulderCameraValueButton.Text = "Disabled"
EnableShoulderCameraValueButton.TextColor3 = Color3.fromRGB(255, 51, 54)
SettingsValuesFolder.ShoulderCameraOnly.Value = false
else
EnableShoulderCameraValueButton.Text = "Enabled" --because original value must be "Disabled"
EnableShoulderCameraValueButton.TextColor3 = Color3.fromRGB(43, 255, 121)
SettingsValuesFolder.ShoulderCameraOnly.Value = true
end
end
local function NoParticlesValueToggled()
if NoParticlesValueButton.Text == "Enabled" then
NoParticlesValueButton.Text = "Disabled"
NoParticlesValueButton.TextColor3 = Color3.fromRGB(255, 51, 54)
SettingsValuesFolder.NoParticles.Value = false
else
NoParticlesValueButton.Text = "Enabled"
NoParticlesValueButton.TextColor3 = Color3.fromRGB(43, 255, 121)
SettingsValuesFolder.NoParticles.Value = true
end
end
local function PerformanceModeValueToggled()
if PerformanceModeValueButton.Text == "Enabled" then
PerformanceModeValueButton.Text = "Disabled"
PerformanceModeValueButton.TextColor3 = Color3.fromRGB(255, 51, 54)
SettingsValuesFolder.PerformanceMode.Value = false
else
PerformanceModeValueButton.Text = "Enabled"
PerformanceModeValueButton.TextColor3 = Color3.fromRGB(43, 255, 121)
SettingsValuesFolder.PerformanceMode.Value = true
end
end
local function SaveToggled()
--local EnableShoulderCameraValue = SettingsValuesFolder.ShoulderCameraOnly
--local NoParticlesValue = SettingsValuesFolder.NoParticles
--local PerformanceModeValue = SettingsValuesFolder.PerformanceMode
local playerSettingsData = {
EnableShoulderCameraValue = EnableShoulderCameraValue.Value,
NoParticlesValue = NoParticlesValue.Value,
PerformanceModeValue = PerformanceModeValue.Value
}
print(playerSettingsData)
print("E")
print(playerSettingsData)
print("sending SETTINGS data to server")
SaveSettingsEvent.OnClientEvent:Connect(function(NewPlayerSettingsData)
playerSettingsData = NewPlayerSettingsData
SaveSettingsEvent:FireServer(NewPlayerSettingsData)
print("fired NewPlayerSettingsData")
end)
SaveSettingsEvent:FireServer(playerSettingsData)
print("fired playerSettingsData")
end
EnableShoulderCameraButton.Activated:Connect(ShoulderCameraValueToggled)
EnableShoulderCameraValueButton.Activated:Connect(ShoulderCameraValueToggled)
NoParticlesValueButton.Activated:Connect(NoParticlesValueToggled)
NoParticlesButton.Activated:Connect(NoParticlesValueToggled)
PerformanceModeButton.Activated:Connect(PerformanceModeValueToggled)
PerformanceModeValueButton.Activated:Connect(PerformanceModeValueToggled)
SaveButton.Activated:Connect(SaveToggled)
SaveSettingsEvent.OnClientEvent:Connect(SaveToggled)
ServerScript:
wait(2)
local DataStoreService = game:GetService("DataStoreService")
local playerSettingsDataStore = DataStoreService:GetDataStore("PlayerSettingsDataStore")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEventsFolder = game.ReplicatedStorage.Remotes
local SaveSettingsEvent = RemoteEventsFolder.SaveSettingsEvent
local playerSettingsData = {}
local SaveSettingsEvent = game:GetService("ReplicatedStorage").Remotes.SaveSettingsEvent
game.Players.PlayerAdded:Connect(function(player)
local retrievedSettingsData
--print("Player_"..player.UserId + "joined!")
local suc = pcall(function()
retrievedSettingsData = playerSettingsDataStore:GetAsync(player.UserId)
print(retrievedSettingsData)
end)
print(playerSettingsData)
print(retrievedSettingsData)
if suc then --if they have data
if retrievedSettingsData then
print("player had settings data!")
print(retrievedSettingsData)
local playerSettingsData = {}
playerSettingsData[player.UserId] = retrievedSettingsData -- we create an index which is the player id and put the table in there
print(playerSettingsData)
else --if they dont have data
playerSettingsData[player.UserId] = {
NoParticles = false,
PerformanceMode = false,
ShoulderCameraOnly = false,
}
print("player had no settings data, setting defaults...")
print(playerSettingsData)
end
end
SaveSettingsEvent:FireClient(player,playerSettingsData[player.UserId])
end)
game.Players.PlayerRemoving:Connect(function(player)
-- from what i remember there is no need for pcalls when writing to data stores (correct me if im wrong)
playerSettingsDataStore:SetAsync(player.UserId,playerSettingsData)
print("Player_"..player.UserId + "left")
print(playerSettingsData)
local success, err = pcall(function()
playerSettingsDataStore:SetAsync(player.UserId, playerSettingsData) -- Save the data with the player UserId, and the table we wanna save
end)
if success then
print("player data saved success")
print(playerSettingsData)
else
print("error while saving")
warn(err)
end
end)
local function SaveToggled(player)
local playerUserID = "Player_".. player.UserId
local success, err = pcall(function()
playerSettingsDataStore:SetAsync(player.UserId, playerSettingsData) -- Save the data with the player UserId, and the table we wanna save
end)
print(playerSettingsDataStore)
print(playerSettingsData)
print(playerUserID .."data was sent!")
end
RemoteEventsFolder.SaveSettingsEvent.OnServerEvent:Connect(SaveToggled)