All the doors are in the same folder. All the doors have the same name, and part class. Why is this only turning some doors transparency?
Code:
local C = false local doors = game.Workspace.Doors local UserInputService = game:GetService("UserInputService") UserInputService.InputBegan:Connect(function(Input, gameProcessedEvent) if gameProcessedEvent == false and Input.KeyCode == Enum.KeyCode.X then for i,v in pairs(doors:GetDescendants()) do if v:IsA("BasePart") then if v.Name == "Door" then if C == false then v.Transparency = .5 v.CanCollide = false C = true elseif C == true then v.Transparency = 0 v.CanCollide = true C = false end end end end end end)
You are changing C after each door so even when a door is closed the script closes is again causing some of them to not open at all. You should set C after the loop is done to make sure all doors are open/closed.
Example:
local C = false local doors = game.Workspace.Doors local UserInputService = game:GetService("UserInputService") UserInputService.InputBegan:Connect(function(Input, gameProcessedEvent) if gameProcessedEvent == false and Input.KeyCode == Enum.KeyCode.X then if C == false then for i,v in pairs(doors:GetDescendants()) do if v:IsA("BasePart") then if v.Name == "Door" then v.Transparency = .5 v.CanCollide = false end end end C = true elseif C == true then for i,v in pairs(doors:GetDescendants()) do if v:IsA("BasePart") then if v.Name == "Door" then v.Transparency = .5 v.CanCollide = false end end end C = false end end end)
That worked, but now if I press X again it won't set the transparency to 0.