This remote function has been bothering me lately and I want to know a quick work around to this. I am not sure if this is a Studio/Engine bug, but I am struggling to understand why this is happening.
Context and explanation
- The main idea is to have a Local script detect a “Player Ready” button press and send the player’s details over to a server script to register the player as ready(and register a few of his details as well).
- Problem: Immediately as I start the play test, the remote Function gets invoked for no reason, then later becomes irresponsive and stops working(can’t get invoked again)
- The remote function is in Replicated storage, the local script is in StarterPlayerScripts, while the server script is in the workspace
- Pointer: This seems to be occurring only with remote functions that are called by scripts which go from client to server
Code
local script(StarterPlayerScripts)
local function onReadyPress(playerNumber, button) print("onReadyPress Activated") -- Ready button was pressed if playerNumber == 1 and button == ready1Button then -- checks if player clicks on his own ready button local readyBool = changeButton(button) playerReadyRF:InvokeServer(player.Name, playerNumber, readyBool, TableInstance) elseif playerNumber == 2 and button == ready2Button then local readyBool = changeButton(button) playerReadyRF:InvokeServer(player.Name, playerNumber, readyBool, TableInstance) end end
Server script(workspace[inside a model])
local function onPlayerReady(player, playerName, playerNumber, readyBool, _TableInstance) print(player) print(playerName) print(playerNumber) print(_TableInstance) print(readyBool) if TableInstance == _TableInstance then -- code from here on out registers the player as ready if player1.Value == playerName then ready1 = readyBool elseif player2.Value == playerName then ready2 = readyBool end print(playerName .. " has ready set to : " .. readyBool) end end playerReadyRF.OnServerInvoke = onPlayerReady()
Visual representation of the problem
Every time I play test, the remote function gets invoked and later on doesn’t work
What I tried and tested
- I tried to replicate this in a new place and I got the same results. I basically made a button and had a local script to detect when the button is pressed and then invoke the remote function. The same thing still happened when I pressed play.
- I even deleted the local script and just remained with the server script code and the same thing still happened.
- I tried starting Roblox studio without plugins enabled
- I tried restarting my PC, just incase it was a problem on my end. Same results
- I tried putting the Server script in ServerScriptService instead of the Workspace.model
- Another important pointer: The server script looks like it could be the problem, because it seems to only affect RFs which are used by Scripts that use the .OnServerInvoke event.
So I am starting to doubt myself and wonder what to do to find a solution to this. Is it a bug?.. I don’t know. I do feel like I am doing something wrong, so I would appreciate as much help as I could get.