PlayerID help needed

My goal: Give certain player Ids tools in the serverstorage and change their nametag colour to be yellow.

Issue:
This error passes:
image

And this is the code:

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
if player.UserId == 116571791 then
	game.ServerStorage.Tools:FindFirstChild('AA-12'):Clone().Parent = player.Backpack
	player.Character.HumanoidRootPart:FindFirstChild('NameTag')
	local tag = player.Character.HumanoidRootPart.NameTag
	tag.PlayerName.TextColor3.Color3 = Color3:new(255, 247, 0)
	end
	if player.UserId == 556697206 then
	game.ServerStorage.Tools:FindFirstChild('AA-12'):Clone().Parent = player.Backpack
	player.Character.HumanoidRootPart:FindFirstChild('NameTag')
	local tag = player.Character.HumanoidRootPart.NameTag
	tag.PlayerName.TextColor3.Color3 = Color3:new(255, 247, 0)
	end
	if player.UserId == 53539000 then
	game.ServerStorage.Tools:FindFirstChild('AA-12'):Clone().Parent = player.Backpack
	player.Character.HumanoidRootPart:FindFirstChild('NameTag')
	local tag = player.Character.HumanoidRootPart.NameTag
	tag.PlayerName.TextColor3.Color3 = Color3:new(255, 247, 0)
	end

You’re using if statements rather than elseifs. Replace all of the ifs after the first to else if and it should work.

1 Like


instant error

image
this is the error needed to be fixed

You forgot two end) 's at the bottom which would close the playeradded and the characteradded

By the way, this has a lot of repeating code. Look into functions
https://education.roblox.com/en-us/resources/functions-part-1

I’ve redone this for you but please also look into the articles I provided to have an understanding on what’s going on.
Here:

local function provideGunToPlayer(player)
	game.ServerStorage.Tools:FindFirstChild('AA-12'):Clone().Parent = player.Backpack
	player.Character.HumanoidRootPart:FindFirstChild('NameTag')
	local tag = player.Character.HumanoidRootPart.NameTag
	tag.PlayerName.TextColor3.Color3 = Color3:new(255, 247, 0)
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		if player.UserId == 116571791 or player.UserId == 556697206 or player.UserId == 53539000 then
			provideGunToPlayer(player)
		end
	end)
end)

(Let me know if this doesn’t work I don’t have a way to test it)

2 Likes

Works like a charm, just this part that doesn’t work now.

Is there an error?

30 c haracters

1 Like

image

Nevermind, the whole line is wrong

Change it to
tag.PlayerName.TextColor3 = Color3.fromRGB(255, 247, 0)

Theres still the same error code.

Sorry, I edited my response instead of making a new one. What I said should work

YAY! It works like a charm! Thank you so much baseparts. <33333 If I could set two solutions I would. mwa
image