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.

3 comments
put local pred = false outside
Read my bio.
Using the mouse to get user input is deprecated. Use UserInputService. wait() is deprecated, use Wait()