Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Script not kicking players when required?

Asked by
Robb12 12
5 years ago

I am trying to make this script kick the players once the timer reaches 0, however I have had no luck in trying to get this to work so far this is the code I have

timer = game.ReplicatedStorage:WaitForChild("Timer")
timer.Value = 5


while true do 
    if timer.Value >= 1 then
    timer.Value = timer.Value - 1
    wait(1)
    else return nil 
    end

    end


-- everyone below not working

function update()
    local p = game.Players:GetPlayers()
    if timer.Value == 0 then
    for i = 1, #p do 
    p[i]:Kick()
    end
    end
end

while wait(.33) do 
    update()
end



Also should I be using a remote function/event when kicking clients?

1 answer

Log in to vote
0
Answered by
haba_nero 386 Moderation Voter
5 years ago
Edited 5 years ago

This should work:

local kickreason = "Timer ran out."--Reason for being kicked
local Timer = 5--The timer value--How long before the players get kicked
for i=Timer,0,-1 do--For every second do this
Wait(1)--Wait a second
end
for i, player in pairs(game.Players:GetPlayers()) do--For every player do
player:Kick(kickreason)--Kick all players
end
Ad

Answer this question