I always used a server script, not a local script.
game.Players.PlayerAdded:connect(function(plr)
plr.Chatted:connect(function(msg)
end)
end)
Now we have an event firing when a player chats. But how do we know if the first 7 characters of the message is "/timer "? We use :sub().
game.Players.PlayerAdded:connect(function(plr)
plr.Chatted:connect(function(msg)
if msg:sub(1,7) == "/timer " then
local time = tonumber(msg:sub(8))
end
end)
end)
Now we have checked if they used the correct command and got the length of the time. To actually do the counting down, we will create a new function that creates a hint in workspace.
function countdown(length)
local h = Instance.new("Hint",workspace)
for i = length,1,-1 do
h.Text = tostring(i)
wait(1)
end
h:Destroy()
end
Now we have our countdown function. The last thing to do is to put it all together!
function countdown(length)
local h = Instance.new("Hint",workspace)
for i = length,1,-1 do
h.Text = tostring(i)
wait(1)
end
h:Destroy()
end
game.Players.PlayerAdded:connect(function(plr)
plr.Chatted:connect(function(msg)
if msg:sub(1,7) == "/timer " then
local time = tonumber(msg:sub(8))
countdown(time)
end
end)
end)
Hope I helped!
1 comment
All I needed was to see how to get the second part, but thanks!