I want it to take all the players not just the player model ( sorry for my english , bassicaly , when I enter the game and use it on someone it aint work and I guess it's becuase of ~~~~~~~~~~~~~~~~~ (game.Workspace.Player) ~~~~~~~~~~~~~~~~~)
the function is this one
p = game.Players:getPlayerFromCharacter(game.Workspace.Player)
How to make it take all player models not just the oe in the solo play?
To get all the players you can use :GetChildren()
and pairs
to get all the children. This is an example of GetChildren.
local workspacechildren = workspace:GetChildren() print(#workspacechildren) --Should print how much things are direct children of workspace.
This is pairs:
for _,v in pairs(workspace:GetChildren()) do print(v.Name) --Should print all of the Items in Workspace. end
Now we get all the players:
for _,v in pairs(workspace:GetChildren()) do if v.ClassName == "Player" then --Just incase. print(v.Name)--Print all of the players names. v.Character.Torso.CFrame = CFrame.new(0,0,0) --Teleport the Characters to 0,0,0 Instance.new("ForceField", v.Character)--Give the players forcefields. end end
Just edit the above script.
I hope this helps!
EDIT
Perci1 Found an error. I meant to say game.Players:GetChildren()
.
for _,v in pairs(game.Players:GetChildren()) do --I just copy and pasted my last script so I didn't have to type the whole thing again. I should be more careful next time! BTW I do know there are no players in workspace. I also know that ":IsA("Player")" works also. It's just I'm used to "ClassName" and I used "v" instead of "player" like how adark did because it's just shorter. if v.ClassName == "Player" then --Just incase. print(v.Name)--Print all of the players names. v.Character.Torso.CFrame = CFrame.new(0,0,0) --Teleport the Characters to 0,0,0 Instance.new("ForceField", v.Character)--Give the players forcefields. end end
Lord's answer is incorrect. Like Perci commented, there are no Player
objects in the Workspace.
To get a Table of all the Players in a game, call GetPlayers
on Game.Players
. This functions identically to GetChildren
, except that it will only get Player
objects:
for _, player in ipairs(Game.Players:GetPlayers()) do print(player.Name) end