I wanted to make a tool that if hits a player when activated then it will do damage,but for some reason when i activate the tool,miss and go up to a humanoid it still hits,how can i fix this? Really cant explain it more detailed in text,but heres a video https://youtu.be/ipaIv9afdRY The code:
local Tool = script.Parent.Parent
local Handle = script.Parent
local Idle = script.Idle
local Attack = script.Attack
local invFrames = false
local cooldown = false
Tool.Equipped:Connect(function()
local humanoid = Tool.Parent:WaitForChild("Humanoid")
local LoadIdle = humanoid:LoadAnimation(Idle)
local weld = Instance.new("WeldConstraint")
LoadIdle:Play()
Tool.Activated:Connect(function()
if cooldown == false then
cooldown = true
local humanoid = Tool.Parent:WaitForChild("Humanoid")
local LoadAttack = humanoid:LoadAnimation(Attack)
LoadIdle:Stop()
weld.Part0 = Handle -- welds the tool to the right arm of the player holding it so it would look like the player is attacking with the tool
weld.Part1 = humanoid.Parent["Right Arm"]
weld.Parent = Handle
LoadAttack:Play() -- plays the attack animation
local touched = Handle.Touched:Connect(function(part)
if part.Parent and part.Parent:FindFirstChild("Humanoid") and part.Parent.Name ~= humanoid.Parent.Name and invFrames ~= true then
part.Parent.Humanoid:TakeDamage(10)
invFrames = true
end
end)
LoadIdle:Play()
task.wait(5)
cooldown = false
invFrames = false
else
end
end)
Tool.Unequipped:Connect(function()
local humanoid = Tool.Parent:WaitForChild("Humanoid")
local LoadAttack = humanoid:LoadAnimation(Attack)
LoadIdle:Stop()
LoadAttack:Stop()
end)
end)

2 comments
it didnt fix it,but thank you for trying
Its alright!