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

How come this code with say its the same player when there is more then one?

local Player = game.Players.LocalPlayer
for i, v in pairs(game.Players:GetPlayers()) do
	if v.Name == Player.Name then
		warn("same name! " .. v.Name .. " and " .. Player.Name)
		return
	else
		warn("different name!")
	end
end

This code is ran on a local script, but it says the only player there is the local player? https://imgur.com/5hGeAYA

5 comments

0

So you're the only actual person in the game...?

0

You're getting a table of players "game.Players:GetPlayers()" and checking for the LocalPlayer's name.

0

No there is 2 people in the game

0

The local player is also a part of the table retrieved when you collect all the players. You have a return inside the if statement, so as soon as you find the local player (and you will), it'll stop the for loop and not search for any other player in the table.

0

Also, return is used exactly as it sounds: it is used to return data to whatever called it (usually used for fuctions,modules etc..). Use break if you wish to instantly stop a loop from executing any further.)

1 answer

The script is running on each client, since this is clearly being replicated, judging from your issue.

A foolproof way to do what you're doing is to use PlayerAdded and whatever player is passed from it when it fires. However, it's usually less of a pain to do it on the server than on the client because the client can't read server signals.

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