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