Remote event sometimes won't fire

Everything is “working” its just that the remoteevent sometimes won’t fire at the beginning of the game, which breaks it.
script is located in ServerScriptService
remoteevent fires to the localscript correctly
vote:FireAllClients() is a remoteevent that is firing to the vote local script to activate the voting process

	local function RoundTimer()
	votingTime.Value=true
	task.wait(1)
	
	
	while wait() do
		
		vote:FireAllClients()--the remote event wont fire in actual game but will fire normally in studio testing localserver 1 player
		print("voting system fired")
		for i=intermissionlength, 0,-1 do
			timerwhite:FireAllClients()
			
			seconds=0
			
			inround.Value=false
			wait(1)
			respawn=false
			roundstatus.Value="Round starting in:"..i
			showicon:FireAllClients()
			
		end
		--anextbotspawnsender:FireAllClients()
		showclockicon:FireAllClients()
		for i=roundlength, 0, -1 do
			votingTime.Value=false
			
			if seconds>=TimerWillTurnRedAt then
				timered:FireAllClients()
			else
				timerwhite:FireAllClients()
			end
			inround.Value=true
			wait(1)
			
			seconds+=1
			--print(seconds)
			roundstatus.Value= i
			
			
		end
		for i, nextbotsinworkspace in pairs(workspace.CurrentNextbots:GetChildren()) do
			nextbotsinworkspace:Destroy()
		end
		Destroymap:FireAllClients()
		votingTime.Value=true
		
		warn("HIHIHI")
		vote:FireAllClients()
		
		
	end
	
end

spawn(RoundTimer)

The weird thing is, is that THE REMOTE EVENT WORKS IN STUDIO BUT NOT IN THE ACTUAL GAME!
maybe this has to do with lag or my very messy and uncoordinated scripting
please help, this bug is very annoying and I am losing my patience quickly.

2 Likes

Also, I tried moving the fire all clients out of the wait() loop, but it still does the same thing. Everything is working properly except the remoteevent does not fire.

that kinda messy and waste, i sugget u can change some stuff in server side instead of fire remote to client side

1 Like

the code is kinda messy i undestand what you tried to do but to see what is going on we need to see the localscript

1 Like

What is the vote full name? Can you send the path?

In Studio everything is handled by the client (your computer).
In the game you have the server working as well as the client.

Do you get an error in the output while playing?

Why not use WaitForChild so if an item isn’t loaded yet then the script won’t crash when it doesn’t find it.

no. No error, but it just does not work. (it works fine in studio, but not when you play it in roblox)

local vote=game.ReplicatedStorage.VoteEvents:WaitForChild("WhenToVote")
I did add a waitforchild.

I’m not sure, but this script runs the function immediately, waits 1 second, then you immediately FireAllClients.

Is this a server or local script? If it’s local it only runs on the client so that could be the issue.

It is a serverscript located in serverscriptservice

Wdym by paths? Vote is linked up correctly but it does not fire when playing the actual game on Roblox.

It’s a race condition. What’s happening right now is that the roblox server launches, which results in your code running. However, the player who joined that newly created server is still loading in, which means the server is running FireAllClients before any clients have actually connected to the game. It’ll work in studio since everything is running on your own PC so you dont have to worry about network latency. A really hacky fix to your problem could be to add an infinite wait until at least one player has connected before you call FireAllClients, but typically there are better ways to handle it.

1 Like

instance:GetFullName() will return the file path if it exists. If not, returns nil

Where should I add in the Infinite wait loop? And are there better ways to fix it?

game.Players.PlayerAdded:Connect(function(player: Player)

— your code here

end)
1 Like

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