I’m pretty new to scripting and I’m trying to make a script that kicks the player when the timer hits zero, the timer works but I cant manage to get the if/then part working. It’s probably just a simple solution but I can’t figure it out, I’ve tried multiple things but it doesn’t seem to work.
-Here’s the script
local text = script.Parent
local count = “60”
local zero = “0”
local player = game.Players.LocalPlayer
while true do
count = count - “10”
text.Text = count
task.wait(1)
end
Without a local script you’re gonna have to change game.Players.LocalPlayer to a PlayerAdded connection
-- Number to count down from
local startNumber = 60
-- When a player is added connect this function to it
game:GetService("Players").PlayerAdded:Connect(function(player)
local count = startNumber
while true do
-- "count = count - 1" but compressed into "count -= 1"
count -= 1
-- Text can't be a number so turn it into a string
text.Text = tostring(count)
-- If the new number is less than or equal to 0 kick the player
if count <= 0 then
player:Kick()
end
task.wait(1)
end
end)
-- Number to count down from
local startNumber = 60
-- When a player is added connect this function to it
game:GetService("Players").PlayerAdded:Connect(function(player)
local count = startNumber
while true do
-- "count = count - 1" but compressed into "count -= 1"
count -= 1
-- Text can't be a number so turn it into a string
text.Text = tostring(count)
-- If the new number is less than or equal to 0 kick the player
if count <= 0 then
player:Kick()
end
print(count)
task.wait(1)
end
end)
Whoops I completely forgot to declare the “text” variable ._.
local text = script.Parent
-- Number to count down from
local startNumber = 60
-- When a player is added connect this function to it
game:GetService("Players").PlayerAdded:Connect(function(player)
local count = startNumber
while true do
-- "count = count - 1" but compressed into "count -= 1"
count -= 1
-- Text can't be a number so turn it into a string
text.Text = tostring(count)
-- If the new number is less than or equal to 0 kick the player
if count <= 0 then
player:Kick()
end
task.wait(1)
end
end)
I couldn’t get it so i just seperated it and had it change the text under a different script, but it works now. Thanks for helping me out!
Sorry if this took a little longer than expected though.