Change transparency locally

I’m trying to make a door where you need a certain level to get trough. Till now, it changed the transparency globally but I only want it to change locally. This is the code I have now.

the script in a normal script in the door itself:

game.Players.PlayerAdded:Connect(function(player)
	while wait() do
		for i, doors in pairs(workspace.LevelDoors:GetChildren()) do
			local door = doors
			for v, values in pairs(door:FindFirstChild("LevelValue")) do -- I get the error "Workspace.LevelDoors.Level1.Script:5: invalid argument #1 to 'pairs' (table expected, got nil)" here
				local levelNeeded = door:FindFirstChild("LevelNeeded")
				if player.leaderstats.Level.Value >= levelNeeded then
					game.ReplicatedStorage.Remotes.doorTransparant:FireClient(player, door)
				end
			end
		end
	end
end)

The script that’s in a localscript in the level door:

local door = script.Parent
local text = script.Parent.SurfaceGui.TextLabel
game.ReplicatedStorage.Remotes.doorTransparant.OnClientEvent:Connect(function(player)
	door.Transparency = 1
	door.CanCollide = false
	text.TextTransparency = 1
end)

Any help is appreciated!

(it’s a bit messy I know)

I wouldn’t rely on a loop to check the players level constantly and instead use .Changed instead like so:

local Player = game.Players.LocalPlayer
local Leaderstats = Player:WaitForChild("leaderstats")

Leaderstats.Level.Changed:Connect(function()
	if Leaderstats.Level.Value >= LevelNeeded then
		Door.Transparency = 1
		Door.CanCollide = false
		Text.TextTransparency = 1
	end
end)

Regarding your error on line 5 that is caused because you haven’t provided a table that pairs requires.

thank you but that still changes the parts transparency globally (or so I think) the problem is in the 1st script

No this is client sided. Make sure to place it within a LocalScript under somewhere the script can run such as a UI for example.

hmm I’ll try thank you (limits)

what do exactly mean with placing the script in a UI, because I can’t seem to make it work in the part itself

this is the script I use now:

local Player = game.Players.LocalPlayer
local Leaderstats = Player:WaitForChild("leaderstats")
local LevelNeeded = script.Parent.levelValue.Value
local Door = script.Parent
local Text = script.Parent.SurfaceGui.TextLabel

Leaderstats.Level.Changed:Connect(function()
	if Leaderstats.Level.Value >= LevelNeeded then
		Door.Transparency = 1
		Door.CanCollide = false
		Text.TextTransparency = 1
	end
end)

LocalScripts don’t run within parts. You need to locate it within StarterGui or StarterPack for example.

I put it in the starterplayerscripts but now this happens

EDIT: forgot what I said I forgot to update server lol. it works thank you!