Data wont be saved or sent to server after firing remote event using Gui, more info in topic

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

  2. 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:
image

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

Did you try enabling studio access to API services?
Cause if it was disabled your datastores may not work, you should find this option in the game settings under security!

Yes, I enabled it.

30char30char30char

I think the server closes before saving your data, maybe try testing the game itself using an alt?

Also you should check this out since it simplifies your task a LOT

Save your player data with ProfileService! (DataStore Module) - Resources / Community Resources - DevForum | Roblox

I have tried it out with an alt, but the data would still not be saved or received. Also, do you think ProfileService, the module you recommended me, would be able to be implemented with Gui?

Ohhhh, I’m not sure what’s the problem then :frowning:

Yeah, I’m pretty sure it can be implemented, but you’ll have to make separate variables for each of it properties :sweat_smile:
or, use an array/table

I finally got it working after 2 days. The ServerScript wasn’t receiving info or getting the passed information from the Client whenever I fire the RemoteEvent. Now that I fixed that, I then had to set up the dictionary. The “PlayerSettingsValue” kepted being empty like this: {}. That’s when I realized that there was a line of code just exactly like this:

local PlayerSettingsValue = {}

That was what kept making the value empty whenever I use this variable in functions and when printing.

Also, this article and this helped out a lot in case if anyone has a problem like me. Thanks to all that have helped.

1 Like