Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Roblox If/then roblox id/username statement?

Asked by 3 years ago

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

Log in to vote
0
Answered by
NGC4637 602 Moderation Voter
3 years ago

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)
0
note: i forgot to mention this was in a local script danielminecrafter66 18 — 3y
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 NGC4637 602 — 3y
0
Thank you so much! this advice worked. :D danielminecrafter66 18 — 3y
Ad
Log in to vote
0
Answered by
sngnn 274 Moderation Voter
3 years ago

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).

Log in to vote
0
Answered by 3 years ago

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

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. NGC4637 602 — 3y

Answer this question