It just refused to work. It is like it doesn't even give me an error.. Even though one of the teams is true during the event.
wait(.5) local plr = game.Players.LocalPlayer local char = plr.Character or plr.CharacterAdded:Wait() local UserInputService = game:GetService("UserInputService") local Key = "Q" local Visible = true local function Visibility(Var) if Var then if plr.Team == ("Foundation Personnel") or plr.Team == ("Internal Security Department") then wait(.8) for _, Part in pairs(char:GetDescendants())do if Part:IsA("BasePart") or Part:IsA("MeshPart") then Part.Transparency = 0 char.Head.face.Transparency = 0 char.HumanoidRootPart.Transparency = 1 end end end else if plr.Team == ("Foundation Personnel") or plr.Team == ("Internal Security Department") then wait(.8) for _, Part in pairs(char:GetDescendants())do if Part:IsA("BasePart") or Part:IsA("MeshPart") then Part.Transparency = 1 char.Head.face.Transparency = 1 end end end end end UserInputService.InputBegan:Connect(function(Input,GameStuff) if GameStuff then return end if Input.KeyCode == Enum.KeyCode[Key] then if Visible then Visibility(false) Visible = false else Visibility(true) Visible = true end end end)
Any ideas?
It would be helpful if you could give a little more information about the problem. To me, the first thing that comes to mind is that under the InputBegan
event gameStuff
is true. Why are you returning when gameStuff
is true?
This should fix it:
wait(.5) local plr = game.Players.LocalPlayer local char = plr.Character or plr.CharacterAdded:Wait() local UserInputService = game:GetService("UserInputService") local Key = "Q" local Visibility = 0 local function ToggleVisibility(toggle) -- Reverse the visibility -- You could also replace the if-statement with this: "Visibility = Visibility == 0 and 1 or 0" -- See http://lua-users.org/wiki/TernaryOperator) if Visibility == 0 then Visibility = 1 else Visibility = 0 end if plr.Team.Name == "Foundation Personnel" or plr.Team.Name == "Internal Security Department" then wait(.8) for _, Part in pairs(char:GetDescendants())do if (Part:IsA("BasePart") or Part:IsA("MeshPart")) and Part.Name ~= "HumanoidRootPart" then Part.Transparency = Visibility char.Head.face.Transparency = Visibility end end end end UserInputService.InputBegan:Connect(function(Input,GameStuff) if Input.KeyCode == Enum.KeyCode[Key] then ToggleVisibility() end end)
Note: I have also cleaned up the code a little bit. When programming you should always try to adhere to what is called the DRY (do not repeat yourself) principle. There is no need to repeat that if statement and for loop.