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

What did I do wrong?

Asked by 9 years ago

When I press Q I go invisible like planned but only my head becomes visible again. Also my cooldown doesn' work.

 CanLaunch = true
cooldown = 3
cloaktime = 5
if CanLaunch == true then local player = game.Players.LocalPlayer:GetMouse()
 player.KeyDown:connect(function(key)
  if string.lower(key) == "q" then CanLaunch = false
   lPlyr = game.Players.LocalPlayer
   targets = lPlyr.Character
   for i, target in pairs(targets:GetChildren()) do
    if target:IsA("Part") then
     target.Transparency = .9
     end end
   wait(cloaktime)
   for i, target in pairs(targets:GetChildren()) do
    if target:IsA("Part") then
     target.Transparency = 0
     target.HumanoidRootPart.Transparency = 1
     wait(cooldown)
     CanLaunch = true
    end end end end) end
1
try removing .HumanoidRootPart.Transparency = 1... that might cause your torso and limbs to be invisible. FearMeIAmLag 1161 — 9y
0
That is irrelevant, actually. The HumanoidRootPart is normally fully transparent. adark 5487 — 9y

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

FearMeIAmLag didn't list a reason that the HumanoidRootPart was broken, so I don't think they really knew.

The line is broken because HumanoidRootPart is a member of the Character, not the current target in the loop. This causes an error. Additionally, each part would wait(cooldown) before letting the next part in the loop become opaque again.

Moving those two lines outside of the for loop fixes both of those issues. (Also, adding an 's' to the target before HumanoidRootPart)

 CanLaunch = true
cooldown = 3
cloaktime = 5

if CanLaunch == true then local player = game.Players.LocalPlayer:GetMouse()
    player.KeyDown:connect(function(key)
        if string.lower(key) == "q" then CanLaunch = false
            lPlyr = game.Players.LocalPlayer
            targets = lPlyr.Character
            for i, target in pairs(targets:GetChildren()) do
                if target:IsA("Part") then
                    target.Transparency = .9
                end
            end
            wait(cloaktime)
            for i, target in pairs(targets:GetChildren()) do
                if target:IsA("Part") then
                    target.Transparency = 0
                end
            end
            targets.HumanoidRootPart.Transparency = 1
            wait(cooldown)
            CanLaunch = true
        end
    end)
end
Ad

Answer this question