Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

When Game loads it only give tool to one player?

this sisa very long script but I need to show you all of it to understand so I will put this in where I have the problem --Bob and then Ill close it off with --/Bob so when my game loads when I server test it only gives the tool to one player which is the second player that loaded so Im thinking somewhere there needs to be a waitforchild or a complete wait() please help me I will give a rep thanks johndeer2233 how Can I fix This?

-- 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
  -- **Bob**
	-- if certain Maps/Gives Tools
if ChosenGameClone.Name == "OfficeMap"then
	function GiveToolThrowingKnife()
	local name2 = game.Players:FindFirstChild(name)
	if name2 then
	local playersBackpack = name2:WaitForChild("Backpack")
	if playersBackpack then
	local ThrowingKnife = game.ServerStorage.ThrowingKnife
	if ThrowingKnife then
	local ThrowingKnifeClone = ThrowingKnife:Clone() 
	ThrowingKnifeClone.Parent = playersBackpack
	            end
	        end
	    end
	end
	GiveToolThrowingKnife()
end
	--**/Bob**
	
	--Timer Before Game Starts
for i = 3, 0, -1 do
 h.Text =  "Time Till Game Begins: "..i
wait(1)
end
h.Text = "Game Begins"
-- 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

✓ Accepted answer

Problem

The problem is that you got a for loop that goes through all your players and you change the global variable Name value. Then you use that variable in the if statement to find the player character. So for example, we test this with 2 players the for loop will run two times. The Name variable will first be Player1 then it will change to Player2. Do you get it? You only access one player with that variable.

Solution

I don't know exactly what would be the best in your case but you could add another for loop that goes through the players and gives them the throwing knife one by one. This could be implemented inside the if statement.

Is this clear enough?

1 comment

0

Yes thanks I understand now thanks to you ill find another way thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.