Server not receiving remote event at ALL?

I’m making a keybinds system but the actual data list for the server to store is on the client, so I opted to use some not optimal methods of saving this, I am currently having a bug with my game right now as the data is not saving properly and the server is printing nothing in-game, however, this works normally in Roblox studio for some reason?

When I fire the events to the server, it does not print anything at all in the in-game console log, however when I test by myself in studio it does?

local function saveKeybinds()
	print(keybindsData.current)
	remoteEvents.SaveKeybinds:FireServer(keybindsData.current)
end

local function saveSettings()
	print(gameSettingsData.current)
	remoteEvents.SaveSettings:FireServer(gameSettingsData.current)
end

local function onPlayerRemoving(player: Player)
	if player == localPlayer then
		saveKeybinds()
		saveSettings()
		print("Sent")
	end
end

Server

local function saveKeybinds(player: Player, keybinds) -- Doesn't even run
	print(player, keybinds)
	local convertedKeybinds = keybindsData:convertToString(keybinds)
	print(convertedKeybinds)
	
	local success = pcall(function()
		keybindsDataStore:SetAsync(player.UserId, convertedKeybinds)
		print(keybindsDataStore:GetAsync(player.UserId))
	end)
	print(success)
end

local function saveSettings(player: Player, gameSettings) -- Doesn't even run
	print(player, gameSettings)
	local success = pcall(function()
		settingsDataStore:SetAsync(player.UserId, gameSettings)
	end)
	print(success)
end

remoteEvents.SaveKeybinds.OnServerEvent:Connect(saveKeybinds)
remoteEvents.SaveSettings.OnServerEvent:Connect(saveSettings)
1 Like

can you send the rest of the client that runs the functions?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")
local Players = game:GetService("Players")

local keybindsData = require(ReplicatedStorage.Modules.Data.Keybinds)
local gameSettingsData = require(ReplicatedStorage.Modules.Data.GameSettings)

local remoteEvents = ReplicatedStorage.RemoteEvents

local localPlayer = Players.LocalPlayer

local function setKeybinds(updatedKeybinds)
	local convertedKeybinds = keybindsData:convertToEnum(updatedKeybinds)
	
	keybindsData:setCurrent(convertedKeybinds)
end

local function setSettings(updatedSettings)
	gameSettingsData:setCurrent(updatedSettings)
end

local function saveKeybinds()
	print(keybindsData.current)
	remoteEvents.SaveKeybinds:FireServer(keybindsData.current)
end

local function saveSettings()
	print(gameSettingsData.current)
	remoteEvents.SaveSettings:FireServer(gameSettingsData.current)
end

local function onPlayerRemoving(player: Player)
	if player == localPlayer then
		saveKeybinds()
		saveSettings()
		print("Sent")
		print("Sometihng")
	end
end

Players.PlayerRemoving:Connect(onPlayerRemoving)
remoteEvents.SetKeybinds.OnClientEvent:Connect(setKeybinds)
remoteEvents.SetSettings.OnClientEvent:Connect(setSettings)

Here is the whole server data manager aswell:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")

local keybindsData = require(ReplicatedStorage.Modules.Data.Keybinds)
local gameSettingsData = require(ReplicatedStorage.Modules.Data.GameSettings)

local remoteEvents = ReplicatedStorage.RemoteEvents

local keybindsDataStore = DataStoreService:GetDataStore("Keybinds")
local settingsDataStore = DataStoreService:GetDataStore("GameSettings")

local function onPlayerAdded(player: Player)
	local userId = player.UserId

	local success, keybinds = pcall(function()
		return keybindsDataStore:GetAsync(userId)
	end)
	
	print(success, keybinds)

	if not success or not keybinds then
		keybinds = keybindsData:convertToString(keybindsData.default)
		warn("REVERTING TO DEFAULT KEYS")
	end

	remoteEvents.SetKeybinds:FireClient(player, keybinds)
	
	local success, gameSettings = pcall(function()
		return settingsDataStore:GetAsync(userId)
	end)
	
	print(success, gameSettings)
	
	if not success or not gameSettings then
		gameSettings = gameSettingsData.default
		warn("REVERTING TO DEFAULT SETTINGS")
	end
	
	remoteEvents.SetSettings:FireClient(player, gameSettings)
end

local function saveKeybinds(player: Player, keybinds)
	print(player, keybinds)
	local convertedKeybinds = keybindsData:convertToString(keybinds)
	print(convertedKeybinds)
	
	local success = pcall(function()
		keybindsDataStore:SetAsync(player.UserId, convertedKeybinds)
		print(keybindsDataStore:GetAsync(player.UserId))
	end)
	print(success)
end

local function saveSettings(player: Player, gameSettings)
	print(player, gameSettings)
	local success = pcall(function()
		settingsDataStore:SetAsync(player.UserId, gameSettings)
	end)
	print(success)
end

game:BindToClose(function()
	remoteEvents.SaveKeybinds:FireAllClients()
	remoteEvents.SaveSettings:FireAllClients()
end)

Players.PlayerAdded:Connect(onPlayerAdded)
remoteEvents.SaveKeybinds.OnServerEvent:Connect(saveKeybinds)
remoteEvents.SaveSettings.OnServerEvent:Connect(saveSettings)

if the server isnt printing anything in game, did you try switching from the client console to the server console?

The server DOES print something when I do this:

task.wait(10)
saveSettings()
saveKeybinds()

Screenshot 2025-02-17 151200

(Yes, this is the SERVER log)

Are you the only player in the server? Is it possible that the server is ending before the events are processed? You might need to use BindToClose to get the events to process reliably.

You can test if this is the problem by seeing if:

game:BindToClose(function()
    print("Stalling server closing.")
    task.wait(5)
    print("Server closing now.")
end)

prevents your problem. This should stall the server from ending for 5 seconds. I wouldn’t personally recommend this because it’s not guaranteed, but realistically all events like that should be processed in 5 seconds so in reality it’s fine.

2 Likes

I tried implementing this into my code, sadly, I still had the same issue.

1 Like

I saw that u used the PlayerRemoving event from the Players Instance on a client sided script trying to see if the localplayer left. I think saving it regularly would fix it?

1 Like

Yeah, I was thinking of doing this kind of system which saves it every minute or so, I’m not sure how it would work though because what if players just left before the 60 seconds? Im looking for a solution that makes it work for the player leaving

Why not getting data from remotevents and storing it in a table (in a serverscript) and then when the player leaves, it saves?

1 Like

line 63 uses game:BindToClose() and fires all clients, which does not yield, and so the server doesn’t run whatever function

i would use a remotefunction instead which does yield, it doesn’t have a function to fire all clients, but you can do so with iteration

maybe that’ll work?

1 Like

Okay, i’ll try implementing remote events for the :BindToClose(), do you think this “yielding” would also work for a playerRemoving event on the server?

Wait isn’t the :BindToClose() function called when all the players left?

1 Like

Yes, or when the server shutdowns, but I think this yielding idea would work for a playerRemoving event, since remoteFunctions apparently yield like he said

yes, in that case you wouldnt need to iterate over every player (since theres only one)

but server shutdowns and any similar event that remove players in bulk would have players iterated over

and if youre concerned about the player not being there, any references to the player object are kept even after they leave, so that you can get any data needed.

Isn’t this easier to implement? (The remoteevent that stores in table)

i dont think you can yield a playerremoving event like bindtoclose, as the player is going to leave anyways

1 Like

Yeah, that’s the issue, it doesn’t even work for the player.Removing on client, so I want to fix that one first

the issue is that the client is trying to fire the server after the player is gone, which won’t work

if it does work somehow (or if im wrong), then you won’t see any of the effect unless you’re in studio and can access the console after server shutdown

i would put the playerRemoving event onto the server and put the functionality there