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

How to Kick All Players Using a Script?

Asked by
Wyqkrn 9
5 years ago

I have seen some answers to this question, but it isn't working for me at the moment. I wanted to kick all players in the server (up to 6) when the value inside a NumberValue hit 0 or lower. The NumberValue is named Health and is located in

game.Workspace.Wall

Anyone have any pointers?

3 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Player has a method called Kick for kicking the player off the server, with an optional parameter for what message to show them. The NumberValue class, as well as some of the other ones such as StringValue, also have an event that fires for whenever the value is changed called Changed. Given this information, all that needs to be done is check if the value is less than or equal to 0 in a function connected to the Changed event, and then call the kick method on every player if it is.

local Players = game:GetService("Players")
game.Workspace.Wall.NumberValue.Changed:Connect(function(value)
    if value <= 0 then
        local players = Players:GetPlayers()
        for i, player in ipairs(players) do
            player:Kick("get out")
        end
    end
end)
Ad
Log in to vote
0
Answered by
BashGuy10 384 Moderation Voter
5 years ago
Edited 5 years ago

Use for do loops

for i, v in pairs(game.Players:GetChildren()) do
    if v then
        v:Kick("Message here")
    end
end

Edit the script to your needs

Links:

https://developer.roblox.com/en-us/articles/For-Loops

https://www.youtube.com/watch?v=UsrtGk5E71w

Log in to vote
0
Answered by
lucas4114 607 Moderation Voter
5 years ago

Put this script anywhere on the server:

game.Workspace.Wall.Health.Changed:connect(function(value)
    if value <= 0 then
        for i,Player in pairs(game.Players:GetChildren()) do
            Player:Kick("Lol bye")
        end
    end
end)
0
"connect" has been depreciated. Use "Connect" instead. davidgingerich 603 — 5y
0
is depreciated* Gameplayer365247v2 1055 — 5y

Answer this question