OnServerEvent not working

.OnServerEvent seems to not run at all, there are no errors.
Screenshot 2023-03-06 at 10.14.15 PM

Client:

local rs = game:GetService("ReplicatedStorage")
local enterMatchRemote = rs.EnterMatchRemote
local leaveMatchRemote = rs.LeaveMatchRemote

exitMatchButton.MouseButton1Up:Connect(function()

   print("run")
   exitMatchButton.Visible = false
   leaveMatchRemote:FireServer(player)
   camera.CameraType = Enum.CameraType.Custom
end)

Server:

local rs = game:GetService("ReplicatedStorage")
local enterMatchRemote = rs.EnterMatchRemote
local leaveMatchRemote = rs.LeaveMatchRemote

leaveMatchRemote.OnServerEvent:Connect(function(player)
	print("remote fired")
	for i,v in playerList do
		print(i.. " | i")
		print(v.. " | v")
	end
end)

The function :FireServer() doesn’t require the parameter player, OnServerEvent will automatically detect who send the remote event.

-- Local Script
RemoteEvent:FireServer()


-- Server Script
RemoteEvent.OnServerEvent(player):Connect(function()
       -- Logic
end)

I’m aware, the code still doesn’t work though; .OnServerEvent still doesnt run though. print(“remote fired”) doesnt work

Try using this

exitMatchButton.MouseButton1Click:Connect(function()

I know that thats not the problem because print(“run”) still works

Huh, interestingly enough, I copied and pasted the exact server function on a new server script and the print worked

Was the old script disabled? Cause that is weird.

No, I have no idea whats happening loll

1 Like

Nevermind I found the issue, I defined the function after a while loop so the function was never defined :stuck_out_tongue_winking_eye: i guess i was being silly

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.