RemoteEvent doesn't fire in one script, but does in the other

Hey all,

I’m currently making a horror game, and I want a different number to be sent back when the player wins and loses. I have a remoteEvent named “TeleportToMain” in ReplicatedStorage
that, when fired to the server, decides the number, and teleports you back to the main game with the number as the TeleportData. The function also needs a survived parameter, if its true, it sends back the number + 1, if not, it sends -1.

However, if I send it from the LocalScript responsible to handle things when you win (basically the win script), it fires normally. but when I try the same with the LocalScript responsible for jumpscares (the game over script), it doesn’t seem to actually fire it. I’ve added some prints to check out what’s happening, and it seems the Client side works fine, but it doesn’t get picked up on the server at all. I tried changing the parameters in the loss script to be the exact same line of code as the win one, but nothing happens. Do you happen to know what’s the problem?

  • Loss script:
local event3 = game.ReplicatedStorage.JumpscareEnd

event3.OnClientEvent:Connect(function()
	local jumpScare = player.PlayerGui:WaitForChild("Jumpscare")
	jumpScare.Frame.BackgroundColor3 = Color3.new(1, 1, 1)
	jumpScare.Enabled = true
	local Tween = TweenProperty(jumpScare.Frame, TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), "BackgroundColor3", Color3.new(0, 0, 0))
	Tween:Play()
	Tween.Completed:Wait()
	local Tween2 = TweenProperty(jumpScare.Frame.YouDied, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), "TextTransparency", 0)
	Tween2:Play()
	Tween2.Completed:Wait()
	task.wait(2)
-- problem [
	print("Teleporting")
	game.ReplicatedStorage.TeleportToMain:FireServer(true)
	print("Fired event")
--problem ]
end)
  • Win script: (to show you that it’s the same line of code)
event.OnClientEvent:Connect(function()
	game.ReplicatedStorage.NightEnded:Fire()
	gui.Enabled = true
	encourage.Visible = false
	Time.Visible = false
	encourage.Transparency = 1
	main.Transparency = 1
	main.Visible = true
	local tweenAppear = Ts:Create(main, TweenInfo.new(1), {BackgroundTransparency = 0})
	tweenAppear:Play()
	tweenAppear.Completed:Wait()
	workspace.Sounds.MainBeep:Play()
	wait(0.4)
	
	for i = 1, 9 do
		wait(0.175)
		alarmAppear(Time)
	end
	Time.Visible = true
	task.wait(2)
	
	encourage.Visible = true
	local tweenAppear2 = Ts:Create(encourage, TweenInfo.new(1), {TextTransparency = 0})
	tweenAppear2:Play()
	task.wait(3)
	game.ReplicatedStorage.TeleportToMain:FireServer(true) -- Right here
end)

Like I said, both of these are LocalScripts, The loss script is in StarterPlayerScripts,
and the other one is in a ScreenGui in StarterGui. (I’m guessing the issue might be here)

Any help appreciated!

3 Likes

I have no idea, this should not be happening, however I found a forum post that could help:
P.S please read the whole thing before trying solutions as most of them wont work

1 Like

I’ve moved the loss script code to the win script, hoping it works :confused:

1 Like

Hello everyone who’s still here!

I have officially solved the problem, and now I know what the mistake was.

Basically, my game had a timer system, so I had a while true do loop that counted up every 60 seconds. The reason my teleport script didn’t work is because the OnServerEvent event was written AFTER the loop, meaning it wasn’t connected.
Since the win condition was put inside the timer loop, it fired when it needed to, and the loop would break.
The loss script however wasn’t, and since you need to die for it to fire, chances are, the timer loop wouldn’t be finished → didn’t connect the OnClientEvent event → didn’t pick up the loss condition → Problem.

I have solved the issue by putting the timer loop in a task.spawn(function()) function.

PLEASE BE AWARE OF THIS ISSUE WITH LOOPS, AS THE OUTPUT DOESN’T SAY ANYTHING, AND YOU BASICALLY HAVE NO IDEA WHAT COULD OR COULDN’T BE HAPPENING

Thanks to everyone for trying to help, I appreciate it!

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