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

6 comments

0

is this in a localscript? Players.LocalPlayer is nil on server scripts

0

yeah, its probably a script, change it to a localscript.

0

what I'm trying to do doesn't work if its a local script so maybe there is another way to do it

0

is there a way I can do it with a server script?

0

no u can't localplayer is nil in a server script, you have to use game.Players.PlayerAdded for server scripts

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.