So I want to make something that happens based on how many players
Ex:
Explode every player
for i,v in pairs(workspace:GetChildren()) do
for count = 1, #players do
--explode all players
end
end
So I want to make something that happens based on how many players
Ex:
Explode every player
for i,v in pairs(workspace:GetChildren()) do
for count = 1, #players do
--explode all players
end
end
k so you have a part and that part will explode same count as players in the game.
doing local players = game.Players:GetPlayers() is prob good.
Creating explosion is your thing
I don’t know what you mean, but you need to change the workspaceGetChildren to game.Players:GetPlayers() and change the if line to #game.Players:GetPlayers
oh so you dont want every part in the workspace to explode oo
You’d make a for loop getting all the players then make a variable local player = game.Players:GetPlayers
Then another loop for I = 1, #player do
Sorry hard typing on phone
in this case you wanna explode every player?
local plrs = game.Players:GetPlayers()
for i = 1,#plrs do
local player = plrs[i]
player.Character.HumanoidRootPart -- put an explosion instance in a certain bodypart of the player
end
If you wanna explode em putting an explosion do:
for _, player in ipairs(game.Players:GetPlayers()) do
local boom = Instance.new("Explosion", player.Character.HumanoidRootPart)
boom.Position = boom.Parent.Position
end
And that’s it, can’t be easier than that. No need to destroy explosions later or save things on variables
try using this
if #game.Players:GetPlayers() >= 1 then -- How many players are in the game
-- explode all players
end
That won’t work or make sense, cuz there is no way a server can have 0 players without start to shut off, all he wants is to iterate through players
He can change the number to check if … players are in the game
Still nonsense.
for _, player in ipairs(game.Players:GetPlayers()) do
--Code, player is the variable that holds the current iterated player, and player.Character is the character of the current iterated player
end
With that for loop he can do whatever he wants and runs once per player
local plrs = game:GetService("Players"):GetPlayers() -- the players in the game
local num_plrs = #plrs -- numbers of players in the game
for _, plr in ipairs(plrs) do -- loop through the players
if num_plrs > 0 then -- change "0" to whatever minimum number you want
-- do stuff
end
end
You would have to run this script after the game has finished loading as running it on a server script that starts immediately after the server starts could cause bugs
I would personally do one of these two
local Players = game:GetService("Players")
for _, player in pairs(Players:GetPlayers()) do -- iterate over all the players
local character = player.Character -- the character of the player we are exploding
do -- unnecessary but visually separates the character variable from the explosion code
-- explode the character
end -- unnecessary but visually separates the character variable from the explosion code
end
local Players = game:GetService("Players")
function Explode(character)
-- explode the character
end
for _, player in pairs(Players:GetPlayers()) do -- iterate over all the players
local character = player.Character -- the character of the player we are exploding
Explode(character)
end
With this code:
for _, player in ipairs(game.Workspace.Dummies:GetChildren()) do
local boom = Instance.new("Explosion", player.HumanoidRootPart)
boom.Position = boom.Parent.Position
end
I got this:
robloxapp-20210108-1027545.wmv
And if you add a wait(.1)
robloxapp-20210108-1028510.wmv
But u want it for players so the fixed code for you would be:
for _, player in ipairs(game.Players:GetPlayers()) do
local boom = Instance.new("Explosion", player.Character.HumanoidRootPart)
boom.Position = boom.Parent.Position
end