Remote Events Not Working With My Countdown I Made

I’m trying to make a countdown that counts down from 5 to 0, while changing lights on my light post at the same time how I want them to. I want it to fire this countdown for all players when someone clicks the “Start Race” button. I first started by making one script that did it all (with no remote events), which I put in the StartGui. I got some help with it to understand that I need to use Remote Events to accomplish this. So, I took the code from the original script and tried using Remote Events.

I need help with the scripts I made to do this, as they’re not doing anything when I click the “Start Race” button, even though there are no apparent errors in the output. I’m likely doing something wrong with the Remote Events and how I integrated them, as I’m new to them.

Here’s a screenshot of the Explorer, as well as the contents of the Script and LocalScript I’m trying to make work.

image

In Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEventCountdown")

local text = game.StarterGui.ScreenGui.Countdown
local button = game.StarterGui.ScreenGui.StartRace
local seconds = game.ReplicatedStorage.Time

text.Visible = false

button.MouseButton1Click:connect(function(play)
	text.Visible = true
	RemoteEvent:FireAllClients()
end)

In LocalScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEventCountdown")

RemoteEvent.OnClientEvent:connect(function()

local text = game.StarterGui.ScreenGui.Countdown
local button = game.StarterGui.ScreenGui.StartRace
local seconds = game.ReplicatedStorage.Time

text.Text = seconds.Value -- Makes the text in the TextLabel the same as what is in the "Time" Value under ScreenGui.

--text.Visible = false

local function PreStage()
	
	local prestagelights = game.Workspace["Racing System"]["Countdown Lights"].RaceTimer3.StageSigns.PreStageLights:FindFirstChildOfClass("PointLight")
	local prestagelightsparts = game.Workspace["Racing System"]["Countdown Lights"].RaceTimer3.StageSigns.PreStageLights:GetChildren()
	
for _, prestagelightsparts in pairs(prestagelightsparts) do
   
    if prestagelights then
        prestagelights.Enabled = true
    end
end

for _, prestagelightsparts in pairs(prestagelightsparts) do
    prestagelightsparts.Material = Enum.Material.Neon
	end
end


local function Stage()
	
	local stagelights = game.Workspace["Racing System"]["Countdown Lights"].RaceTimer3.StageSigns.StageLights:FindFirstChildOfClass("PointLight")
	local stagelightsparts = game.Workspace["Racing System"]["Countdown Lights"].RaceTimer3.StageSigns.StageLights:GetChildren()
	
for _, stagelightsparts in pairs(stagelightsparts) do
   
    if stagelights then
        stagelights.Enabled = true
    end
end

for _, stagelightsparts in pairs(stagelightsparts) do
    stagelightsparts.Material = Enum.Material.Neon
	end
end


local function Red()
	local RedLights = game.Workspace["Racing System"]["Countdown Lights"].RaceTimer3.RedLights.Lights:FindFirstChildOfClass("PointLight")
	local RedLightsParts = game.Workspace["Racing System"]["Countdown Lights"].RaceTimer3.RedLights.Lights:GetChildren()
	
for _, RedLightsParts in pairs(RedLightsParts) do
   
    if RedLights then
        RedLights.Enabled = true
    end
end

for _, RedLightsParts in pairs(RedLightsParts) do
    RedLightsParts.Material = Enum.Material.Neon
	end
end


local function Yellow()
	local YellowLights = game.Workspace["Racing System"]["Countdown Lights"].RaceTimer3.YellowLights.Lights:FindFirstChildOfClass("PointLight")
	local YellowLightsParts = game.Workspace["Racing System"]["Countdown Lights"].RaceTimer3.YellowLights.Lights:GetChildren()
	
for _, YellowLightsParts in pairs(YellowLightsParts) do
   
    if YellowLights then
        YellowLights.Enabled = true
    end
end

for _, YellowLightsParts in pairs(YellowLightsParts) do
    YellowLightsParts.Material = Enum.Material.Neon
	end
end


local function Green()
	local GreenLights = game.Workspace["Racing System"]["Countdown Lights"].RaceTimer3.GreenLights.Lights:FindFirstChildOfClass("PointLight")
	local GreenLightsParts = game.Workspace["Racing System"]["Countdown Lights"].RaceTimer3.GreenLights.Lights:GetChildren()
	
for _, GreenLightsParts in pairs(GreenLightsParts) do
   
    if GreenLights then
        GreenLights.Enabled = true
    end
end

for _, GreenLightsParts in pairs(GreenLightsParts) do
    GreenLightsParts.Material = Enum.Material.Neon
	end
end



local function Countdown() -- Makes the countdown code into a local function.
	
text.Visible = true

if seconds.Value == 5 then
	PreStage()
end

while seconds.Value > 0 do
	seconds.Value = seconds.Value - 1
	wait(1)
 script.Parent.Text = seconds.Value -- Makes the TextLabel countdown from whatever number is in the "Time" Value under ScreenGui.

if seconds.Value == 3 then
	Stage()
end

if seconds.Value == 2 then
	Red()
end

if seconds.Value == 1 then
	Yellow()
end

if seconds.Value == 0 then
	script.Parent.Text = "GO!"
	Green()
end

if script.Parent.Text == "GO!" then
	wait(1)
	text.Visible = false
	end 
end
-- Waits for _ seconds, and then makes the TextLabel not visible.

end
-- When the TextButton value is 0, it becomes "GO!" instead of 0.
--[[ button.MouseButton1Click:connect(function(play)
	text.Visible = true
	Countdown()
end)
-- Makes it so that when you hit the "StartRace" button, it makse the TextLabel visible and plays the "Countdown()" function. --]]

end)

Thanks for any help,

1 Like

This is a simple error.

Change

local text = game.StarterGui.ScreenGui.Countdown
local button = game.StarterGui.ScreenGui.StartRace

to

local text = script.Parent.ScreenGui.Countdown
local button = script.Parent.ScreenGui.StartRace

What your doing wrong is mentioning game.StarterGui and changing its settings for future players connecting, when really you should be mentioining the current GUI.

For the local script ^

For server script V

local text = game.StarterGui.ScreenGui.Countdown
local button = game.StarterGui.ScreenGui.StartRace

is to be changed to.

    for i,v in pairs(game.Players:GetPlayers()) do
     local text = v.PlayerGui.ScreenGui.Countdown
     local button = v.PlayerGui.ScreenGui.StartRace
     local text2 = game.StarterGui.ScreenGui.Countdown
     local button2 = game.StarterGui.ScreenGui.StartRace
     end

As your failing to mention all of the players in-game guis and the gui for future players connecting

2 Likes

user the block https://www.roblox.com/library/4483892622/Block-That-Counts-Backwords

In the Server Script now it says, “Unknown global ‘text’” and “Unknown global ‘button’” below in the MouseButton1Click:connect function.

image

Thanks for your help! I figured out that it was a few issues, including the way I used RemoteEvents, and also where I called my function.