Script made to print text when it finds someone with a specific name doesn't work

Im attempting to make a system where admins or people get a specific avatar thats different from 3 other randomly chosen avatars. My test is to see if it works by printing something if it finds my username, but it never prints the text. Here is my code

local Players = game:GetService("Players")

while wait(0.5) do
	
	if Players.Name == ("Xenaside") then
		print("IT WORKS")
else

	local CharRound = math.random(1,3)
	
	if CharRound == 1 then
		game.StarterPlayer:FindFirstChild("StarterCharacter"):Destroy()
		game.StarterPlayer.Characters.One.StarterCharacter:Clone().Parent = game.StarterPlayer
		print("One Select")
		
	elseif CharRound == 2 then
			game.StarterPlayer:FindFirstChild("StarterCharacter"):Destroy()
			game.StarterPlayer.Characters.Two.StarterCharacter:Clone().Parent = game.StarterPlayer
		print("Two Select")

	elseif CharRound == 3 then
		game.StarterPlayer:FindFirstChild("StarterCharacter"):Destroy()
		game.StarterPlayer.Characters.Three.StarterCharacter:Clone().Parent = game.StarterPlayer
		print("Three Select")
		end
	end
end

Anyone know what’s going on? All answers appreciated.

Players.Name will print the name of the Players service which is “Players”. You just need to sort through the children of ‘Players’ like so:

for i, v in pairs(Players:GetPlayers()) do
    if v.Name == "Xenaside" then
        -- code here
    end
end

I also recommend changing the if statement to check for the UserId instead of a player name as your code will require an update if anyone ever changed their Roblox name. The code would then become the following:

for i, v in pairs(Players:GetPlayers()) do
    if v.UserId == 847431372 then
        -- code
    else
        -- more code
    end
end

Happy coding and good luck on your game.

2 Likes

Thank you! Ill test this out, ill tell you if it works

Works well, thanks for helping me out!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.