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

How could I get all the players name to give a tool?

Asked by 8 years ago

So I have a script and I will give you the whole one how can I get the game.Players.Player.Backpack usually I can get this but not now so I need help please ill put a Bob where the part starts and a /Bob where it ends please help me get the players name?

-- Made By johndeer2233
-- Make a hint
h = Instance.new("Hint",game.Workspace)

--If there is more than 1 player
while true do
if game.Players.NumPlayers > 1 then
   -- Choosing A Map
   maps = game.ServerStorage.Maps:GetChildren() 
   h.Text =  "Choosing A Map"
   wait(3) 
   ranGame = math.random(1,#maps)
   ChosenGame = maps[ranGame]   
   h.Text =  "Map Chosen: "..ChosenGame.Name
   wait(3)
   ChosenGameClone = ChosenGame:Clone()
   ChosenGameClone.Parent = game.Workspace
   wait(3)
-- Teleport Players To Map
local spawns = ChosenGameClone.Spawns:GetChildren()
    for i,v in pairs(game.Players:GetPlayers()) do
        name = v.Name
        check = game.Workspace:FindFirstChild(name)
        if check then
          checkHumanoid = check:FindFirstChild("Humanoid")
         if checkHumanoid then
            v.Character:MoveTo(spawns[i].Position)
            end             
        end 
    end

    -- Gives Tools **Bob**
    function GiveToolThrowingKnife()
    local name = 
    local check = game.Players:FindFirstChild(name)
    if check then
    local playersBackpack = check:WaitForChild("Backpack")
    local ThrowingKnife = game.ServerStorage.ThrowingKnife
    local ThrowingKnifeClone = ThrowingKnife:Clone() 
    ThrowingKnifeClone.Parent = playersBackpack
        end
    end
    --Timer Before Game Starts
for i = 15, 0, -1 do
 h.Text =  "Time Till Game Begins: "..i
wait(1)
end
h.Text = "Game Begins"
-- if certain Maps
if ChosenGameClone == "OfficeMap"then
    wait(3)
    GiveToolThrowingKnife()
end
-- **/Bob**
-- Countdown till game ends
for i = 180, 1, -1 do   
 h.Text =  "Time Left: "..i
wait(1)
end
h.Text = "Game Ended"
ChosenGameClone:Destroy()
else    
   h.Text =  "There Is Not Enough Players To Start"
   wait(3)  
    end
 wait(1)
end

1 answer

Log in to vote
0
Answered by
Kryddan 261 Moderation Voter
8 years ago

As I said in your last post you can use a for loop that loops through all players and give them a throwing knife one by one. Let's look at your GiveToolThrowingKnife function. Instead of checking after one single player lets add a for loop.

local players = game.Players:GetChildren()
for i = 1, #players do

    local ThrowingKnife = game:GetService("ServerStorage").ThrowingKnife:Clone()--we can even clone it here to make it more compact and you don't have to make a lot of variables
    ThrowingKnife.Parent = players[i].Backpack --I also removed the variable where you located the players backpack because it takes up a lot of space and it's not neccesary with that many variables

end

This is a very simple way of doing it but it was mostly created to give you a idea what you can do. You can use this or improve it further if you want.

0
Thnajs a lot you helped me twice see I got stuck on how can I get all the players I tried getchildren getplayers its the for loop thanks alot kryddan johndeer2233 439 — 8y
Ad

Answer this question