Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I don't know why this script for cloaking people is not working?

Asked by
bt6k 23
4 years ago

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?

0
What is the reason for: "if GameStuff then return end"? blazar04 281 — 4y

1 answer

Log in to vote
0
Answered by
blazar04 281 Moderation Voter
4 years ago
Edited 4 years ago

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.

1
Still not working. Honestly I forgot why I wrote gamestuff. This is such an old code that I don't know why I did that. It still doesn't work though. The game that I am using it on, what it does it when someone joins a team, the team is added to teams, but if it is not being used, it is stored in a folder. Any solution still? It is not working in the first place by the way. No errors, nothing. bt6k 23 — 4y
1
What it is supposed to do, is make you just invisible, but it is not working. bt6k 23 — 4y
0
I ran this code in studio without checking if the player is on one of the teams and it worked. The issue must be with the if statement, so put a print statement after the if statement and see if it prints. If not, then the player is not on that team. blazar04 281 — 4y
0
Oh I see! You are checking if the plr.Team is a string, however plr.Team refers to a team object (https://developer.roblox.com/en-us/api-reference/class/Team) not a string. So you would need to check for plr.Team.Name (see my updates to the script). Should work now blazar04 281 — 4y
View all comments (4 more)
1
Thank you so much! Now I have another problem... The second script with the particles. I tried to copy what you did with the plr.Team.Name and it doesn't seem to be working.. bt6k 23 — 4y
0
How does it not work? Any errors or anything? If there aren't any errors you need to put print statements are parts you think aren't being ran and see if they are. I could help you with this problem too if you made another post and I could see the script if you would like. blazar04 281 — 4y
0
I see it blazar04 281 — 4y
Ad

Answer this question