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

Invisible Script Not Turning Back To Non-Invisible?

Asked by
PolyyDev 214 Moderation Voter
6 years ago
Edited 6 years ago

I have made a script so that when "e" is pressed the character turns invisible and the walkspeed changes. The first part works fine but getting it to turn back to normal is the hassle. It won't turn back to its non-invisible state and its really confusing me. I am not getting any errors at all and I don't see why it wouldn't be working.

Here is the code: (Its in a localscript)

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
wait(3)
local char = player.Character
print(char.Name)

mouse.KeyDown:Connect(function(key)
        local pred = false  
        if pred == false then   
        pred = true
        char.LeftFoot.Transparency = 1
        char.LeftHand.Transparency = 1
        char.LeftLowerArm.Transparency = 1
        char.LeftLowerLeg.Transparency = 1
        char.LeftUpperArm.Transparency = 1
        char.LeftUpperLeg.Transparency = 1
        char.LowerTorso.Transparency = 1
        char.RightFoot.Transparency = 1
        char.RightHand.Transparency = 1
        char.RightLowerArm.Transparency = 1
        char.RightLowerLeg.Transparency = 1
        char.RightUpperArm.Transparency = 1
        char.RightUpperLeg.Transparency = 1
        char.UpperTorso.Transparency = 1
        char.Head.Transparency = 1
        char.Head.face.Transparency = 1
        char.GlassesBlackFrame.Handle.Transparency = 1
        char.TwitterBird.Handle.Transparency = 1
        char["Ultra-Fabulous Hair Brown"].Handle.Transparency = 1
        char.Humanoid.WalkSpeed = 40

    elseif pred == true then
        pred = false
        char.LeftFoot.Transparency = 0
        char.LeftHand.Transparency = 0
        char.LeftLowerArm.Transparency = 0
        char.LeftLowerLeg.Transparency = 0
        char.LeftUpperArm.Transparency = 0
        char.LeftUpperLeg.Transparency = 0
        char.LowerTorso.Transparency = 0
        char.RightFoot.Transparency = 0
        char.RightHand.Transparency = 0
        char.RightLowerArm.Transparency = 0
        char.RightLowerLeg.Transparency = 0
        char.RightUpperArm.Transparency = 0
        char.RightUpperLeg.Transparency = 0
        char.UpperTorso.Transparency = 0
        char.Head.Transparency = 0
        char.Head.face.Transparency = 0
        char.GlassesBlackFrame.Handle.Transparency = 0
        char.TwitterBird.Handle.Transparency = 0
        char["Ultra-Fabulous Hair Brown"].Handle.Transparency = 0
        char.Humanoid.WalkSpeed = 16
end
    end)

If anyone could help that would be much appreciated.

0
put local pred = false outside cakelight 0 — 6y
0
Read my bio. hiimgoodpack 2009 — 6y
0
Using the mouse to get user input is deprecated. Use UserInputService. wait() is deprecated, use Wait() hiimgoodpack 2009 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
wait(0.5)
local player = game:GetService("Players").LocalPlayer
local char = player.Character

function onKeyPress(inputObject)
    if inputObject.KeyCode == Enum.KeyCode.E then
        for i,v in pairs(char:GetChildren()) do
            if v:IsA("BasePart") then
                v.Transparency = 1
                if v:FindFirstChildOfClass("Decal") then  v:FindFirstChildOfClass("Decal").Transparency = 1 end
            elseif v:IsA("Accessory") then
                v:FindFirstChild("Handle").Transparency = 1
            end
        end
        char.Humanoid.WalkSpeed = 40
    end
end

game:GetService("UserInputService").InputBegan:Connect(onKeyPress)

function onKeyPress1(inputObject)
    if inputObject.KeyCode == Enum.KeyCode.E then
        for i,v in pairs(char:GetChildren()) do
            if v:IsA("BasePart") then
                if v.Name ~= "HumanoidRootPart" then
                    v.Transparency = 0
                    if v:FindFirstChildOfClass("Decal") then  v:FindFirstChildOfClass("Decal").Transparency = 0 end
                end
            elseif v:IsA("Accessory") then
                v:FindFirstChild("Handle").Transparency = 0
            end
        end
        char.Humanoid.WalkSpeed = 16
    end
end

game:GetService("UserInputService").InputEnded:Connect(onKeyPress1)

If this helped you solve your question then accept answer! :)

0
wait() is deprecated, use Wait() hiimgoodpack 2009 — 6y
0
Also, you did not need to define gameProcessedEvent because you never used that variable. hiimgoodpack 2009 — 6y
0
Wait() is deprecated and removed gameProcessedEvent. abnotaddable 920 — 6y
0
Itturns invisible whenever any key is pressed PolyyDev 214 — 6y
0
But don't worry I modified your method and it works so I will just accept it. PolyyDev 214 — 6y
Ad

Answer this question