How would I make the script go through all the players, and effect all of them? (Global script in the Workspace) Here's two things I tried:
01 | for I,v in pairs (game.Players:GetPlayers()) do |
02 | local randomCoor = coordinates [ math.random(#coordinates) ] |
03 | local knife = game.ServerStorage.Knife:Clone() |
04 | knife.Parent = v:WaitForChild( "Backpack" ) |
05 | game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "Round In Progress..." |
06 | c = v.Character or v.CharacterAdded:wait() |
07 | c.Torso.CFrame = CFrame.new(randomCoor) |
08 | wait( 60 ) |
09 | for I,v in pairs (game.Players:GetPlayers()) do |
10 | c = v.CharacterAdded:wait() |
11 | v.Character.Humanoid.Health = 0 |
12 | end |
13 | end |
Those didn't effect all players though, it only effected 1 player at random, for both. This is just a cutout of my script, but please help with
Simple, let's say you want to damage every player in the game by half their health. You could say this:
1 | for i, v in pairs (game.Players:GetChildren()) do -- i is what player the for loop is currently on, the v is the payer itself. |
2 |
3 | --Here in the loop, you can say whatever you want to happen to everybody. |
4 | v.Character.Humanoid.Health = 50 |
5 |
6 | end |
You need to create a clone of the knife and give the clone to each player, otherwise the knife will not be in ServerStorage for the next iteration over the players:
game.ServerStorage.Knife:Clone().Parent = v:WaitForChild("Backpack")
You are also waiting for 60 seconds for each player before then killing each player. It is unusual that you are iterating over the players inside a loop that is iterating over all the players. I can't tell what your intentions are there. If you tell me what you want it to do, I might be able to help further.