Event not getting received on the Server Side?

Greetings,

I have a script that should receive an event, but for some reason the event fires from the local side but it does not receive on the server side. I get no errors or warnings. Please help! Code is down below.

The code (Local side):

SendGUI:FireServer()

The code (Server side):

SendGUI.OnServerEvent:Connect(function(player)
	print("The event got fired")
	if players:FindFirstChild(player.Name) then
		Participants.Value += 1
		print("Value should've gotten changed by now: " ..Participants.Value)
		
		local value = Instance.new("NumberValue", workspace.Racetrack1.Players)
		value.Name = player.Name
	end
end)

Thanks!

1 Like

Change to:

local player = game.Players.LocalPlayer

SendGUI:FireServer(player)
print("Fired")

when firing a remote event isnt the player who fired it always sent as the first parameter anyway?

2 Likes

It fires on the local side as I said, but nothing happens on the server side.

That’s just me not thinking, apologies.

I’ve tried this and it worked for me fine. Can you show the full code on both the client and server?

I would like to see the full server script, I might have an idea of why this is happening

Local side:

--Services
local RS = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer

--Events
local SendGUI = RS:WaitForChild("Racing"):WaitForChild("SendGUI")

--Items
local debounce = false
local frame = script.Parent
local button = frame.Button
local announcement = frame.Announcement
local decision = frame.Decision

SendGUI.OnClientEvent:Connect(function(show)
	if show == 1 then
		frame.Visible = true
		announcement.Text = "A race is going to start in 30 seconds, would you like to participate?"
		announcement.UIStroke.Color = Color3.new(0.0588235, 0.490196, 0)
		announcement.Visible = true
		button.Visible = true
	elseif show == 2 then
		frame.Visible = true
		announcement.Text = "Not enough players to start a race!"
		announcement.UIStroke.Color = Color3.new(0.701961, 0, 0)
		announcement.Visible = true
	end
end)

button.MouseButton1Click:Connect(function()
	if debounce == false then
		debounce = true
		
		SendGUI:FireServer(player)
		print("The event got fired on the local side")
		
		button.Visible = false
		decision.Visible = true
		
		wait(1)
		debounce = false
	end
end)

Server side:

task.wait(3)
--Services
local players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")

--Events
local SendGUI = RS:WaitForChild("Racing"):WaitForChild("SendGUI")

--Items
local Participants = workspace.Racetrack1.Participants
local Ongoing = workspace.Racetrack1.Ongoing

local Racetrack1Parts = workspace.Racetrack1:GetDescendants()
local ToTeleport

for _, part in (Racetrack1Parts) do
	if part.Name == "ToTeleport" then
		ToTeleport = part
	end
end

local StartBarrier = workspace.Racetrack1:WaitForChild("StartBarrier")
local show = 0


while true do
	task.wait(20)
	
	Participants.Value = 0
	local totalplayers = 0
	for i, v in pairs(players:GetChildren()) do
		totalplayers += 1
	end
	if totalplayers >= 1 then
		print("Enough players, time to get some speed going over here.")
		local show = 1
		SendGUI:FireAllClients(show)
		
		task.wait(30)

		if Participants.Value >= 1 then
			for i, player in pairs(workspace.Racetrack1.Players:GetChildren()) do
				if players:FindFirstChild(player) then
					print("Participant still exists")
				else
					Participants.Value =- 1
				end
			end
			if Participants.Value > 1 then
				for i, player in pairs(workspace.Racetrack1.Players:GetChildren()) do
					players:FindFirstChild(player).Character.HumanoidRootPart.CFrame = ToTeleport.CFrame
				end
				
				
			else
				local show = 2
				for i, player in pairs(workspace.Racetrack1.Players:GetChildren()) do
					if players:FindFirstChild(player) then
						SendGUI:FireClient(player)
					end
				end
			end
		else 
			local show = 2
			SendGUI:FireAllClients(show)
		end
	else
		print("There weren't enough players")
		print("Not enough players as you can see: " ..totalplayers.. ". It's not my fault :(")
	end
end

SendGUI.OnServerEvent:Connect(function(player)
	print("The event got fired")
	if players:FindFirstChild(player.Name) then
		Participants.Value += 1
		print("Value should've gotten changed by now: " ..Participants.Value)
		
		local value = Instance.new("NumberValue", workspace.Racetrack1.Players)
		value.Name = player.Name
	end
end)
1 Like

Keeping the post on the front page.

1 Like

Aha, the loop you put before the event yields the script, you need to put the event connection before the loop.

Wait where?
char limit 30 bruh

1 Like

This would send out SendGUI.OnServerEvent:Connect(function(player, player)

You don’t need to add in the player parameters, because it is already added. You only needed to add the player paramater when using :FireClient(player) so it knows which player to fire to.

edit nevermind already saw the replies

In the server script, you have a while true do loop which yields the script.
You need to put SendGUI.OnServerEvent before it.

SendGUI.OnServerEvent:Connect(function(player)
	-- Stuff there :)
end)

while true do
	-- Stuff here :)
end
1 Like

He already said that he mistaken and I have removed that from my script

3 Likes

Well, that seemed to work, thanks a lot, never expected this to be the issue. It’s one of those scenarios that are really annoying. Thank you once again!

2 Likes

ikr :skull:
I had those situations before, I’m glad your problem is solved though :slight_smile:

1 Like

Yeah my idea was pretty spot on you just had a loop before the OnServerEvent. It seems you already have resolved it now however, so that’s good.

1 Like

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