You’re welcome for the help. Remember to mark the solution.
Hold on, when I bound the other attack to the damage() function its now doing 3x as much damage?
Because you aren’t disconnecting the touched event so each time the event fires a new touched event is created and so each time you attack a player all of those events will fire.
Have one remote event fire for the damage function and use parameters to separate the different kinds of tool animations. Then you can set the damage to your own choosing by adding a damage variable. And if the damage is higher than what you expected you can lower it.
It is gonna run the touched event even if you don’t swing, maybe make a variable at the top that is a boolean and in the touched function add a if statement that checks if it is true and make it true when you swing.
try this, it might not work, i didn’t test it
local tool = script.Parent
local hasSwung = false
tool.LeftSwing.OnServerEvent:Connect(function()
hasSwung = true
tool.Hitbox.Touched:Connect(function(hit)
if hasSwung == true then
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent.Humanoid:TakeDamage(25)
hasSwung = false
end
end
end)
end)
What do you mean by have a remote event fire for the damage function?
Before I answer that question, are you sure all of your attacks aren’t being called at the same time?
My left attack is being called when I press E, my right attack is being called when I press R. Basically it fires 2 separate remote events for E and R
Once you fire a remote event make sure to add some time in between the amount of time another remote event can be called.
Alright, after that what do I do?
Well, after you add some debounce to your main script, your problem should be solved.
Alright it finally works now, thanks for your help.
This whole chain is extremely over complicated the solution is extremely simple.
local activated = false
YourTool.Activated:Connect(function()
activated = true -- sets activated to true everytime it is activated
YourTool.Touched:Connect(function(TouchInstance)
if activated then
if TouchInstance:WaitForChild("Humanoid") then
local hum = TouchInstance:WaitForChild("Humanoid")
hum:TakeDamage(yourdamageamounthere)
activated = false
end
end
end