Ranned Into A Scripting Problem

I am making a chat command activated door script that starts a timer as soon as the door open but it’s not working any clue on what I did wrong?
This is the script:

game.Players.PlayerAdded:connect(function(plr)
	plr.Chatted:connect(function(msg)
		if plr.Name == "Tamegogeta13" then
			if msg == "/e Begin" then
			elseif t == 25 then
				repeat
					t = t-1
					game.StarterGui.Timer.Text = "Time: "..t
					script.Parent.Transparency = 1
					script.Parent.CanCollide = false
					task.wait(1.5)
					if t == 15 then
						game.StarterGui.Timer.Text = "DOORS ARE CLOSING SOON"
						script.Parent.Transparency = 1
						script.Parent.CanCollide = false
						task.wait(5)
						t = 15
					end
					if t == 5 then
						game.StarterGui.Timer.Text = "DOORS ARE CLOSING NOW"
						script.Parent.Transparency = 1
						script.Parent.CanCollide = false
						task.wait(5)
						t = 5
					end
				until
				t == 0
				script.Parent.Transparency = 0
				script.Parent.CanCollide = true
				game.StarterGui.Timer.Text = "DOORS ARE CLOSED"
				task.wait(5)
				game.StarterGui.Timer.Text = "If You Did Not Make It Back Leave Game"
				task.wait(10)
				game.StarterGui.Timer.Text = "Thank You For Attending The Trials"
				task.wait(10)
				game.StarterGui.Timer.Text = "Everyone That Made It Back Get Back In STS Formation"
				task.wait(10)
				game.StarterGui.Timer.Text = "Time: 0"
			end
		end
	end)
end)

It’s the timer that is not responding at all which breaks the whole script but nothing errors or shows in output even a print doesn’t show.

if msg == "/e Begin" then is not doing anything since it’s immediately followed by an elseif. Was this intended behavior?
You are also trying to reference a GUI element from a server-sided script. Server can’t reference someones’ GUI, you would need to make a RemoteEvent to fire what you want Timer.Text to be to the client and have them set their own GUI.

I’m using a chat command that opens a door and fires a timer the /e Begin works now it’s the timer

but if you could give an example that would be great

For establishing remote events you’re going to want to read the Remote Functions and Events tutorial. I can help simplify the logic happening within your timer though. It can still be done using the repeat-until model, but simpler would be a for-loop:

--Door only has to be set to open state once
script.Parent.Transparency = 1
script.Parent.CanCollide = false

for i = t, 0, -1 do
    local textString

	if i == 15 then
		textString = "DOORS ARE CLOSING SOON"
        --fire your event to send textString to all clients here
		task.wait(5)--appears you want this to pause the count-down for 5 seconds
	elseif i == 5 then
		textString = "DOORS ARE CLOSING NOW"
        --fire your event to send textString to all clients here
		task.wait(5)
	else
		textString = "Time: " .. i
        --fire your event to send textString to all clients here
	end

	task.wait(1)
end
--After loop is done, you only need to set it to closed state once too
script.Parent.Transparency = 0
script.Parent.CanCollide = true

After which you’d similarly send a string for your other messages to the clients.
Ideally you’d only have one call to fire the remote event, but since you want to pause the timer momentarily, this is the easiest demonstration of that: Fire it first, then wait.

StarterGui is not the same as PlayerGui. StarterGui is the original location of Gui that automatically get cloned into the player’s PlayerGui after loaded.

You can read more here:
Intro to GUIs

I did this and now it is doing this https://gyazo.com/f41c0a2b9ae0e00a0e6b65c6d4bbc4da
this the line is erroring: game.Players.LocalPlayer.PlayerGui.Timer.Text = "Time: "…t

I’ll give this a try aswell if it don’t work I will let you know

The server cannot access a “LocalPlayer”. The LocalPlayer is the player of the given client. You’ll have to iterate through each player to update it. Either that or have the client handle everything Gui related.

I noticed and it’s still doing it

https://gyazo.com/984c03920d87a93b38363edcdeea3236
but text it part of the gui lol this be confusing some times

nvm i have to do a waitforchild im a clumsy dev

THANK YOU SOO MUCH FOR POINTING THIS OUT TO ME i had to do waitforchild and it works now thanks.

1 Like