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