When i add part.Anchored = true, its not activating the part.Touched thing or something idk. But when i remove the part.Anchored = true, its now giving damage. How do i true the anchor and give damage? What is the problem?

local Attack = true

script.Parent.Activated:Connect(function()
wait(0.1)

if Attack == true then		
Attack = false	
local character = script.Parent.Parent
local Humanoid = character:WaitForChild('Humanoid')
local torso = character:WaitForChild('HumanoidRootPart')
	
local part = Instance.new("Part", game.Workspace)
	part.Size = Vector3.new(7.3, 4 ,3)
	part.Anchored = true
	part.CanCollide = false
	part.Transparency = 0.5
	part.CFrame = torso.CFrame+(torso.CFrame.lookVector*3)


	part.Touched:Connect(function(p)
		local hum = p.Parent:FindFirstChildOfClass("Humanoid")
		
		if p.Parent.Name == ("Mob") then
			if script.Parent.CanDamage.Value == true then
				script.Parent.CanDamage.Value = false
				hum:TakeDamage(20)
				wait(0.5)
				script.Parent.CanDamage.Value = true
			end
			
	
		end
		
		
	end)
		

wait(0.15)
part:Destroy()
wait(0.5)
Attack = true	
	
end

end)

6 comments

0

Is this from an NPC?

0

Nah, its players script. When players use this tool this happens.

0

Is this script placed in the Handle of the tool?

0

Nah not in the handle, its parent is tool.

0

Are you doing hit detection by making a part?

0

Yeah, im creating a part front of the character and then doing these things. And one more problem, i want to hit all the mobs who is in the part but it just damage one of them. How do i make the multiple damage?