Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What did I do wrong?

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

2 comments

1

try removing .HumanoidRootPart.Transparency = 1... that might cause your torso and limbs to be invisible.

0

That is irrelevant, actually. The HumanoidRootPart is normally fully transparent.

1 answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.