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

How to access all players?

Asked by 8 years ago

I was wondering, Does this script work? And how do you access all players for like teleporting all players and killing all players? (And how do you access a players backpack? Is it .backpack?) Script :

--[[ To leave comments type -- then your messsage.
    ex. --Add a timer. Put it next to the line you want me to add it to.
]]--
--[[VARIABLES]]--
timertext = script.Parent.Text
mappicked = script.Parent.hasPickedMap
intermissiontime = 20
timertime = 210
playersjoin = game.Players.NumPlayers
--[[FUNCTIONS]]--
--function countplayers
if playersjoin == 4 then
    --function intermission
    repeat 
        wait(1)
        intermissiontime = intermissiontime - 1
        timertext = intermissiontime
    until
    intermissiontime == 0
    --function choosemap
    timertext = "Choosing map..."   
    wait(1) 
    map = math.random(game.Workspace.Folder)
    timertext = map
    map:clone(game.workspace)
    map.Position = "0,0,0"
    --function teleplayers
    timertext = "Teleporting players..."
    --teleportplayers
    --function choosemurderer
    murder = math.random(game.Players)
    game.ServerStorage["Murderer Knife"]:clone(murder.Backpack)
end

Sorry for having a lot of questions, but also, how do you refresh a script, like, make the script reset and run again?

0
If you are trying to make a murder game you should watch the tutorial from the Roblox University. We aren't going to recreate a whole murder game for you. Azmidium 388 — 8y
0
I'm not asking for someone to recreate it for me. -_- I'm just asking some questions. theawesome624 100 — 8y
0
In addition to the answers below, do consider making sure each field exists. ex, If you say "v.Character.Humanoid", this will error if v.Character is nil (might happen if the character hasn't loaded yet). chess123mate 5873 — 8y
0
Yes true but they will most likely be loaded then, but yes, I will make sure theawesome624 100 — 8y

2 answers

Log in to vote
2
Answered by 8 years ago

An easier way to do it is to use a for loop, example:

for i,v in pairs(game.Players:GetPlayers()) do
v.--Whatever you want to do!
end

Hope this helps, if it does, please accept my answer, it gives us both rep!

0
So, like this? for i,v in pairs(game.Players:GetPlayers()) do v.Character.Humanoid.Health = 0 end theawesome624 100 — 8y
0
Exactly! ScriptFusion 210 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

To access all the players you can do this:

local p = game.Players:GetChildren()

for i = 1,#p do
    p[i].CharacterAdded:wait()
    p[i].Character.Humanoid.Health = 0
end

This is the simplest version.

To reset a script, you could

1. Clone it and put in the script's parent, then remove() the script.

2. Make the entire thing a while loop.

0
Line 4 will wait for the player to respawn (which might take minutes!). Instead, you should simply make sure that the Character exists and skip over them if they don't. chess123mate 5873 — 8y
0
True. But I was just showing him how. He should've accepted my answer, cause it was the simplest and easiest to learn :/ TheDeadlyPanther 2460 — 8y

Answer this question