Why this remoteevent not firing?

Hi, im making game but when u click play it runs this

script.Parent.Play.MouseButton1Click:Connect(function()
	print("a")
	game.ReplicatedStorage.Events.TpPlr:FireServer()
end)

But when the code runs it dosent print a2

game.ReplicatedStorage.Events.TpPlr.OnServerEvent:Connect(function(plr:Player)
	print("a2")
	local map = game.Workspace:FindFirstChild("Map")
	
	if map and map:FindFirstChild("Spawns") and #map.Spawns:GetChildren() > 0 then
		plr:RemoveTag("OnLobby")
		

		local ChosenPart = map.Spawns[math.random(1, #map.Spawns:GetChildren())]
		plr.Character.HumanoidRootPart.CFrame = ChosenPart.CFrame + Vector3.new(0, 4, 0)
	end
end)

Please help ty!

1 Like

Are there any errors in the output? An error can cause the whole script to break.

3 Likes

It works for me, are there any errors showing in output?

3 Likes

Looks like it should work. are you sure you are defining the RemoteEvent correctly?

3 Likes

Are you sure this is a Remote Event not a Unreliable Event?

3 Likes

How does the whole server script look like?

3 Likes

The whole server script is this

local voting = require(script.Voting)
game.Players.PlayerAdded:Connect(function(plr)
	plr:AddTag("OnLobby")
end)


	

while true do
	local chosenMap = voting.MapVoting(15)
	local clonedMap = chosenMap:Clone()

	clonedMap.Name = "Map"
	clonedMap.Parent = workspace
	for _, plr in pairs(game.Players:GetPlayers()) do
		if not plr:HasTag("OnLobby") then
			local ChosenPart = clonedMap.Spawns[math.random(1,#clonedMap.Spawns:GetChildren())]
			plr.Character.HumanoidRootPart.CFrame = ChosenPart.CFrame + Vector3.new(0,15,0)
			plr.PlayerGui.MainMenu.Enabled = false
			plr.PlayerGui.VotingUI.VotingFrame.Visible = false
			game.ReplicatedStorage.Events.ChangeCam:FireClient(plr)
		end
	end
	
	task.wait(125)

	clonedMap:Destroy()
	for _, plr in pairs(game.Players:GetPlayers()) do
		plr.Character.HumanoidRootPart.CFrame = game.Workspace.SpawnLocation.CFrame
	end
end
game.ReplicatedStorage.Events.TpPlr.OnServerEvent:Connect(function(plr:Player)
	print("a2")
	local map = game.Workspace:FindFirstChild("Map")
	
	if map and map:FindFirstChild("Spawns") and #map.Spawns:GetChildren() > 0 then
		plr:RemoveTag("OnLobby")
		

		local ChosenPart = map.Spawns[math.random(1, #map.Spawns:GetChildren())]
		plr.Character.HumanoidRootPart.CFrame = ChosenPart.CFrame + Vector3.new(0, 4, 0)
	end
end)

Whole Local

local plr = game.Players.LocalPlayer

script.Parent.Play.MouseButton1Click:Connect(function()
	print("a")
	game.ReplicatedStorage.Events.TpPlr:FireServer()
end)

local on = false
script.Parent.Vote.MouseButton1Click:Connect(function()
	if on == false then
		on = true
		script.Parent.Parent.VotingUI.VotingFrame.Visible = true
	elseif on == true then
		on = false
		script.Parent.Parent.VotingUI.VotingFrame.Visible = false
	end
end)

1 Like

There arent any errors in output.

2 Likes

No there arent any errors in output

2 Likes

It isnt a Unreliable Event its a normal Remote Event

1 Like

The while loop in your server script is blocking the connection, to fix it you’ll need to move it to the bottom like so:

local voting = require(script.Voting)
game.Players.PlayerAdded:Connect(function(plr)
	plr:AddTag("OnLobby")
end)


	


game.ReplicatedStorage.Events.TpPlr.OnServerEvent:Connect(function(plr:Player)
	print("a2")
	local map = game.Workspace:FindFirstChild("Map")
	
	if map and map:FindFirstChild("Spawns") and #map.Spawns:GetChildren() > 0 then
		plr:RemoveTag("OnLobby")
		

		local ChosenPart = map.Spawns[math.random(1, #map.Spawns:GetChildren())]
		plr.Character.HumanoidRootPart.CFrame = ChosenPart.CFrame + Vector3.new(0, 4, 0)
	end
end)

while true do
	local chosenMap = voting.MapVoting(15)
	local clonedMap = chosenMap:Clone()

	clonedMap.Name = "Map"
	clonedMap.Parent = workspace
	for _, plr in pairs(game.Players:GetPlayers()) do
		if not plr:HasTag("OnLobby") then
			local ChosenPart = clonedMap.Spawns[math.random(1,#clonedMap.Spawns:GetChildren())]
			plr.Character.HumanoidRootPart.CFrame = ChosenPart.CFrame + Vector3.new(0,15,0)
			plr.PlayerGui.MainMenu.Enabled = false
			plr.PlayerGui.VotingUI.VotingFrame.Visible = false
			game.ReplicatedStorage.Events.ChangeCam:FireClient(plr)
		end
	end
	
	task.wait(125)

	clonedMap:Destroy()
	for _, plr in pairs(game.Players:GetPlayers()) do
		plr.Character.HumanoidRootPart.CFrame = game.Workspace.SpawnLocation.CFrame
	end
end
1 Like

Thank you so much!!! Now it works!!

1 Like

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