If/then statement help

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

if count == “0” then
player:Kick()
end

local count = “60”
count = count - “10”

get rid of the " " around all numbers, the script thinks they’re strings (words) because of them

first of all, you dont have to use " " (strings) to use it in a textLabel, instead just put tostring() on the Label with the number

text.Text = tostring(count)
if count == 0 then
player:Kick()
end

thanks for the info, i changed the those up but it still wont kick them.

do you got any other reccomendations?

test it in-game cuz you cant kick players in roblox studio

is this on a localscript, or a normal script?

its on the local script under starter gui

you cant kick players in localscripts, you have to put this in the server

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)
  • untested

it works but the only thing is the counter stops as soon as your game loads in which i think may be, because of the function.

see what this prints

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

the print goes down to 0 and kicks them but the text up top stays the same number and doesn’t change.

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)

dont worry i had the text variable up there but it still won’t change the text?

add print(text.Text) after the text = script.Parent

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.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.