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.
- 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)
- The switch code
local GoodLap = game.ReplicatedStorage.GoodLap
local Switcharoo = game.ReplicatedStorage.Switcharoo
GoodLap.OnClientEvent:Connect(function()
Switcharoo:FireServer()
end)
- 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 ![]()
