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

How do I make it so that my Tool does damage only when I click?

Aight so the animation when I click plays when i press but the hit the :TakeDamage(60) happens right away when I don't click like if I just get the Handle(The handle is a square part ) it does damage right away how can i make it so that only if i click it does damage

tool = script.Parent
Handle = tool:WaitForChild("Handle")
player = game.Players.LocalPlayer
mouse = player:GetMouse()
Animation = tool:WaitForChild('Anime')
AnimationTime  = true
tool.Equipped:Connect(function()
	print(tool)

end)

tool.Activated:Connect(function()
	if AnimationTime then
		AnimationTime = false
		local AnimationPlay = player.Character.Humanoid:LoadAnimation(Animation)
		AnimationPlay:Play()
		
		wait(1)
		AnimationTime = true
		
	end
end)


Handle.Touched:Connect(function(hit)
	debounce = false
	if hit and tool.Activated then
		Humanoid = hit.Parent:FindFirstChild('Humanoid')
		if Humanoid then
			Humanoid:TakeDamage(60)
			
			wait(1)
			
			
		end
	end
end)

2 comments

0

Please provide some explanation to your code and what you're trying to accomplish.

0

Im trying to make it so that only when I click it does damage because If i have that tool out and it touches a Humanoid it does damage and instakils right away

1 answer

This is because you didnt make a boolean for the Touched event when it should fire, so it just fires outright and putting the Activated event in the if statement wont do anything. You can fix this by just using a boolean like what i said.

local tool = script.Parent
local Handle = tool:WaitForChild("Handle")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Animation = tool:WaitForChild('Anime')
local AnimationTime  = true
local canTouch = false

tool.Equipped:Connect(function()
    	print(tool)
end)

tool.Activated:Connect(function()
    if not AnimationTime then
        AnimationTime = false
        local AnimationPlay = player.Character.Humanoid:LoadAnimation(Animation)
        AnimationPlay:Play()
	canTouch = true
	AnimationPlay.Stopped:Wait()
        AnimationTime = true
	canTouch = false

    end
end)


Handle.Touched:Connect(function(hit)
    local Humanoid = hit.Parent:FindFirstChild('Humanoid')
    	if Humanoid and canTouch == true then
            Humanoid:TakeDamage(60)
        end
    end
end)

6 comments

0

At line 29 are there suposed to be two == signs?

0

btw it doesn't work idk if u wanted me to add on to it or copy and paste it

0

oops ya theres suppose to be 2 ==

0

changed it

0

for some reason it does not damage or play the aniimation

0

are there any errors

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