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

How do I check if player has certain UserId?

Asked by 2 years ago

I cannot seem to make the script check if the player's UserId is correct.

Here is my code:

local Players = game:GetService('Players')
local Player = Players.LocalPlayer

if script.Parent.PrimaryPart then
    if Player.UserId == 171275787 then
        for i, v in pairs(script.Parent:GetDescendants()) do
            if v:IsA("BasePart") then
                if v ~= script.Parent.PrimaryPart then
                    local wc = Instance.new("WeldConstraint",script.Parent.PrimaryPart)
                    wc.Name = "weld"
                    wc.Part0 = script.Parent.PrimaryPart
                    wc.Part1 = v
                    v.Anchored = false
                    v.CanCollide = false
                    v.Massless = true
                end
            end
        end

        script.putBehind.Disabled = false
    end

end

Please help, Thanks

0
is this in a localscript? Players.LocalPlayer is nil on server scripts OfficerBrah 494 — 2y
0
yeah, its probably a script, change it to a localscript. pepsymax 73 — 2y
0
what I'm trying to do doesn't work if its a local script so maybe there is another way to do it NotchBoy246 4 — 2y
0
is there a way I can do it with a server script? NotchBoy246 4 — 2y
View all comments (2 more)
0
no u can't localplayer is nil in a server script, you have to use game.Players.PlayerAdded for server scripts pepsymax 73 — 2y
0
don’t use UserId on LocalScript. even if it works, hackers can avoid it. if this is in a character you can use GetPlayerFromCharacter. Speedmask 661 — 2y

Answer this question