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)
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.
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.
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.