Why does this not recieve the remoteevent?

So im making a racing game and i needed to use both remote events from a local and server script. Its a server script so for it to work i just made a script that recieved the server script one and sent one from a local script which will work, though it doesnt. I have no idea why.

Here are the scripts.

  1. Server sending the first remoteevent
local part1 = script.Parent
local seat = script.Parent.Parent.VehicleSeat
local checkpointFolder = workspace:WaitForChild("Checkpoints")
local finishLine = workspace.Track1.FinishLine

local raceTouchedParts = {}
local finishLineTouchedCount = 0
local finishLineTouchedTwice = false
local allCheckpointsTouched = false
local raceFinished = false 
local GoodLap = game.ReplicatedStorage.GoodLap
for _, part in pairs(checkpointFolder:GetChildren()) do
	if part:IsA("BasePart") then
		raceTouchedParts[part] = false
	end
end

local Players = game:GetService("Players")


local function fireToLocalPlayer(player)
	GoodLap:FireClient(player)  -- IMPORTANT HERE
end


local function onPartTouch(otherPart)
	if otherPart == finishLine then
		finishLineTouchedCount = finishLineTouchedCount + 1
		print(finishLineTouchedCount)
		print("FinishLine touched.")

		if finishLineTouchedCount == 2 and not finishLineTouchedTwice then
			finishLineTouchedTwice = true
			print("Finish Line Touched Twice")
		end

	elseif otherPart:IsA("BasePart") and checkpointFolder:FindFirstChild(otherPart.Name) and not raceTouchedParts[otherPart] then
		raceTouchedParts[otherPart] = true
		print(part1.Name .. " is touching " .. otherPart.Name)

		local allCheckpointsTouchedTemp = true 
		for part, touched in pairs(raceTouchedParts) do
			if not touched then
				allCheckpointsTouchedTemp = false
				break
			end
		end

		if allCheckpointsTouchedTemp then
			allCheckpointsTouched = true 
			print("All checkpoints touched!")
		end
	end

	if finishLineTouchedTwice and allCheckpointsTouched and not raceFinished then
		print("GoodLap")
		local Player = Players:GetPlayerFromCharacter(seat.Occupant.Parent)
		print(Player.Name)
		GoodLap:FireClient(Player) -- IMPORTANT HERE
		raceFinished = true 
	end
end

local touchConnection = part1.Touched:Connect(onPartTouch)
  1. The switch code
local GoodLap = game.ReplicatedStorage.GoodLap
local Switcharoo = game.ReplicatedStorage.Switcharoo

GoodLap.OnClientEvent:Connect(function()
	Switcharoo:FireServer()
end)
  1. The one recieving the switched remoteevent
local TimeDisplay = script.Parent
local Switcharoo = game.ReplicatedStorage.Switcharoo
local StartTimer = game.ReplicatedStorage.StartTimer
local min = 0
local sec = 0

TimeDisplay.Visible = false

StartTimer.OnServerEvent:Connect(function(player)
	TimeDisplay.Visible = true

	while min < 10 do
		for sec = 0, 59 do
			TimeDisplay.Text = string.format("%02d", min)..":"..string.format("%02d", sec)
			wait(1)
		end
		min = min + 1
	end
	TimeDisplay.Visible = false
	min = 0 
	sec = 0 
end)

Switcharoo.OnServerEvent:Connect(function(player)
	print("test from ".. player.Name) 
	min = 0
	sec = 0
	TimeDisplay.Text = string.format("%02d", min)..":"..string.format("%02d", sec) -- Update the display
	TimeDisplay.Visible = true
end)

Thanks in advance :slight_smile:

Are you sure the client does not receive the remote event request after it’s been fired by the server? What is the local script receiving the remote event parented to?

local GoodLap = game.ReplicatedStorage.GoodLap
local Switcharoo = game.ReplicatedStorage.Switcharoo

GoodLap.OnClientEvent:Connect(function()
	Switcharoo:FireServer()
	print"testttt"
end)

did this and no print. Guess its gotta be an issue there then. It is parented to ServerScriptService

If you’re talking about the local script, then your code wouldn’t work as local scripts can only be ran if they are parented to the following services:


If local scripts are parented to anywhere else such as the ServerScriptService, then it will simply not run.

Ill put it in starterplayerscripts and see.

Works well. Huge thanks for that.

1 Like

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