My script made me feel sick

Okay I think someone didn’t my want
I need to check if that is first player then tp that plr to pos1 if that is second plr then tp to pos2

issue is this part of my script

function ImHere(Count)
	print(Count)
	for i,v in pairs(game.Players:GetChildren()) do
		print(i)
		if i == 1 then
		print("Lets go1")
		v.PlayerGui.ReadyUp.Enabled = false
		v.Character.HumanoidRootPart.Position = pos1
		end
		if i == 2 then
			print("Lets go2")
			v.PlayerGui.ReadyUp.Enabled = false
			v.Character.HumanoidRootPart.Position = pos2
		end
		if i == 3 then
			print("Lets go3")
			v.PlayerGui.ReadyUp.Enabled = false
			v.Character.HumanoidRootPart.Position = pos2
		end
	end
end

AND LOOK THIS OUTPUT


Output : Count is i from first line
But It isn’t pass First statement
Count = 1
statement is if Count == 1 WHAT HOW HOW HOW
Its should print Lets go1

I tried to fix it so many times until im forgetten

Change this part to if v == 1 then

And the same for the others like if v == 2 then

1 Like

I don’t think that would work because v is being set to the player, not the amount of times it has run the for loop

What are you trying to index? The service? It doesn’t go through the if check because the name’s “Players”, you’re checking if the name is “1”. If you want to know how many players there are, #game.Players:GetPlayers() does that.

Therefore, create a variable that determines the amount of players (as stated above), and in your loop, check the number provided by the variable.

but v is player its not number

Change pairs to ipairs.

Pairs are for dictionaries, ipairs are for arrays. When you use game.Players:GetChildren(), it returns an array of players for v and their index for i.

2 Likes

tonumber() well it might work idk

nvm forget it im fixed with my self with

function ImHere()
	for i,v in ipairs(game.Players:GetChildren()) do
		if i == 1 then
			v.Character.HumanoidRootPart.Position = pos1
		else
			if i == 2 then
				v.Character.HumanoidRootPart.Position = pos2
			else
				if i == 3 then
					v.Character.HumanoidRootPart.Position = pos2
				end
			end
		end
	end
end
1 Like