Im trying to make a sword that makes you Invisible when damaged, currently It only makes your body parts (R6) Invisible, works but there Is a problem where It will activate the ability when healing but I want It to only work when damaged
Script:
local Tool = script.Parent
local SoundFolder = Tool.Sounds
local SlashAttack
local Boolens = {
Debounce = false,
CanDamage = false
}
local Animations = { ---Oh boi there Is alot
EquipAnimation = Tool.EquipAnimation,
Idle = Tool.Idle,
Slash = Tool.Slash
}
Tool.Equipped:Connect(function()
SoundFolder.Unsheath:Play()
local Humanoid = Tool.Parent.Humanoid
Humanoid.WalkSpeed = 20
Tool.Handle.Transparency = 0.9
Humanoid.Parent.Head.Transparency = 0.9
Humanoid.Parent.Torso.Transparency = 0.9
Humanoid.Parent["Left Arm"].Transparency = 0.9
Humanoid.Parent["Right Arm"].Transparency = 0.9
Humanoid.Parent["Left Leg"].Transparency = 0.9
Humanoid.Parent["Right Leg"].Transparency = 0.9
local EquipAnimationTrack = Humanoid:FindFirstChild("Animator"):LoadAnimation(Animations.EquipAnimation)
EquipAnimationTrack:Play()
task.wait(0.30)
local Idle = Humanoid:FindFirstChild("Animator"):LoadAnimation(Animations.Idle)
Idle:Play()
Humanoid.HealthChange:Connect(function()
Humanoid.WalkSpeed = 30
Tool.Handle.Transparency = 1
Humanoid.Parent.Head.Transparency = 1
Humanoid.Parent.Torso.Transparency = 1
Humanoid.Parent["Left Arm"].Transparency = 1
Humanoid.Parent["Right Arm"].Transparency = 1
Humanoid.Parent["Left Leg"].Transparency = 1
Humanoid.Parent["Right Leg"].Transparency = 1
wait(5)Humanoid.WalkSpeed = 20
Tool.Handle.Transparency = 0.9
Humanoid.Parent.Head.Transparency = 0.9
Humanoid.Parent.Torso.Transparency = 0.9
Humanoid.Parent["Left Arm"].Transparency = 0.9
Humanoid.Parent["Right Arm"].Transparency = 0.9
Humanoid.Parent["Left Leg"].Transparency = 0.9
Humanoid.Parent["Right Leg"].Transparency = 0.9
end)
Tool.Unequipped:Connect(function()
Humanoid.WalkSpeed = 16
Tool.Handle.Transparency = 0.5
Humanoid.Parent.Head.Transparency = 0
Humanoid.Parent.Torso.Transparency = 0
Humanoid.Parent["Left Arm"].Transparency = 0
Humanoid.Parent["Right Arm"].Transparency = 0
Humanoid.Parent["Left Leg"].Transparency = 0
Humanoid.Parent["Right Leg"].Transparency = 0
Idle:Stop()
end)
end)
Tool.Activated:Connect(function()
if not Boolens.Debounce then
Boolens.Debounce = true
Boolens.CanDamage = true
SoundFolder.Slash:Play()
print("The tool has been clicked")
local Humanoid = Tool.Parent.Humanoid
SlashAttack = Humanoid:FindFirstChild("Animator"):LoadAnimation(Animations.Slash)
SlashAttack:Play()
wait(1)
Boolens.Debounce = false
Boolens.CanDamage = false
end
end)
Tool.Handle.Touched:Connect(function(hit)
local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if Player then
local player1 = game.Players:GetPlayerFromCharacter(Tool.Parent)
local player2 = game.Players:GetPlayerFromCharacter(hit.Parent)
if (player1 ~= nil) and (player2 ~= nil) then
local humanoid = (player2.Character or player2.CharacterAdded:Wait()):FindFirstChildWhichIsA("Humanoid")
if (player1.TeamColor ~= player2.TeamColor) then
if (humanoid ~= nil) and Boolens.CanDamage == true then
Boolens.CanDamage = false
humanoid:TakeDamage(10)
humanoid.WalkSpeed = 10
humanoid.JumpPower = 30
wait(5)
humanoid.WalkSpeed = 16
humanoid.JumpPower = 50
end
end
end
else
local NPCHumanoid = hit.Parent:WaitForChild("Humanoid")
if NPCHumanoid and Boolens.CanDamage == true then
Boolens.CanDamage = false
NPCHumanoid:TakeDamage(10)
NPCHumanoid.WalkSpeed = 10
NPCHumanoid.JumpPower = 30
wait(5)
NPCHumanoid.WalkSpeed = 16
NPCHumanoid.JumpPower = 50
end
end
end)

3 comments
I also see that you set the tool's transparency and walkspeed whenever you change the player's visibility, you could also add those into the function (just make more parameters and possibly rename the function for clarity).
Where should I place the script?
This is replacing your script, I specified the start and end.