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

Roblox If/then roblox id/username statement?

I am trying to make a part that if it detects my userid, it will change the BrickColor to gold, and I have tried this:

if game.Players.LocalPlayer.userid == ("1108976841") then
	script.parent.BrickColor = BrickColor.new("Gold")
end

This does not seem to work. Does anyone have a solution?

3 answers

✓ Accepted answer

if you are using a local script, this is what you should do:

if game.Players.LocalPlayer.UserId == 1108976841 then -- no brackets and no quotation marks, also, It has to be UserId, not userid (sad).
	script.Parent.BrickColor = BrickColor.new("Gold")
end

if you are using a server script, then you should do this:

game.Players.PlayerAdded:Connect(function(player) -- you use the player parameter
	if player.UserId == 1108976841 then -- the rest is basically the same
		script.Parent.BrickColor = BrickColor.new("Gold")
	end
end)

3 comments

0

note: i forgot to mention this was in a local script

0

oh ok, just use the first script then however, please make sure that the local script is a descendant (inside of) the player, or the player's character or else it will not work

0

Thank you so much! this advice worked. :D

userid (which is actually supposed to be UserId) requires a number value - not a string:

game.Players.LocalPlayer.UserId == 1108976841

Also, LocalPlayer won't work in a server script (if that's what you're using; if not, be aware that a LocalScript will not display the color for anyone else).

Please excuse me for my dumb mistakes, but I followed all of this advice and none of it worked.

1 comment

0

btw, local scripts only work when their ancestor is a player (meaning it works inside playerGui, player scripts, backpack etc.), a player's character or ReplicatedFirst.

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