I'm making a fighting game, and I want it so players can continue attacking the monster by spam clicking (or hold clicking), but the current system I have isn't working. I have it so when the weapon handle is touched and if the name of the object that touched it is a 'Hitbox' then it will fire the rest of the code. It works but you have to keep moving in order for the touched event to fire otherwise if you stand still and keep clicking it doesn't do any damage.
How do I make this better? This is in a local script, in a server script I just subtract the value from the health that I sent over, it's nothing much. I was thinking maybe checking if the Hitbox was hit instead? Or should I instead check if the player is within range of the hitbox using magnitude and then if they click with the weapon it would fire to the server? I don't know the best approach for this.
local tool = script.Parent
local handle = script.Parent.Handle
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character
local humanoid = character:WaitForChild('Humanoid')
local animation = Instance.new('Animation')
animation.Parent = script.Parent
animation.AnimationId = 'rbxassetid://210638956'
local animTrack = humanoid:LoadAnimation(animation)
local canAttack = true
tool.Activated:Connect(function()
if canAttack then
animTrack:Play()
handle.Touched:Connect(function(hit)
if hit.Parent ~= character and hit.Name == 'Hitbox' then
if canAttack and hit.Parent:FindFirstChild('Hitbox') then
local damageEvent = hit.Parent:FindFirstChild('damageEvent')
if damageEvent then
damageEvent:FireServer(script.Parent.Damage.Value)
wait()
canAttack = false
end
end
end
end)
animTrack.KeyframeReached:Connect(function()
canAttack = true
end)
end
wait(.25)
canAttack = true
end)

1 comment
This did not help at all, this is exactly what I already have. I want to make it so they can keep clicking to attack the monster (which has a custom health system using IntValues) and it will take damage away, or hold click where you will keep slashing with the tool and it will do damage.