I have created a script that plays an animation when I press Q or E, but I also made a sword and I don't know how to make it so when I press Q or E and the sword touches a Humanoid the humanoid takes damage? So far I've gotten this, can someone explain what I've done wrong and/or maybe fix the script? Thank you !
--\ Animation Script //-- (idk if it helps or not)
--\\ VARIABLES //--
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local uis = game:GetService("UserInputService")
local swing = Instance.new("Animation")
swing.AnimationId = "rbxassetid://04696235743"
local debounce = false
local spin = Instance.new("Animation")
spin.AnimationId = "rbxassetid://4672766085"
--\\ SWING //--
function SwingAtt(inputObject, gameProcessEvent)
if not debounce then
if inputObject.KeyCode == Enum.KeyCode.E then
debounce = true
humanoid:LoadAnimation(swing):Play()
wait(1.5)
debounce = false
end
end
end
uis.InputBegan:Connect(SwingAtt)
--\\ SPIN //--
function SpinAtt(inputObject, gameProcessEvent)
if not debounce then
if inputObject.KeyCode == Enum.KeyCode.Q then
debounce = true
humanoid:LoadAnimation(spin):Play()
wait(2.5)
debounce = false
end
end
end
uis.InputBegan:Connect(SpinAtt)
--\ Damage Script (need help with) //--
local swing = Enum.KeyCode.E
local spin = Enum.KeyCode.Q
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local damage = 0
if player.swing then
damage = 15
script.Parent.Touched:Connect(function(part1)
if part1.Parent:WaitForChild("Humanoid") then
part1:TakeDamage(damage)
end
end)
end
if player.spin then
damage = 30
script.Parent.Touched:Connect(function(part2)
if part2.Parent:WaitForChild("Humanoid") then
part2.Parent.Humanoid:TakeDamage(damage)
end
end)
end

6 comments
Is there any errors?
It’s a local script you need it to be a normal script and as I don’t work with weapons/tools I can’t help
No error in the Output or Script Analysis, it's also a normal script inside the tool's handle
The take damage would need to be done in a server script. You can add a touched event on the server side then check for a playing animation on hit
I'm sorry but I don't know how to do that really, could you maybe help?
I've added the animation script if it helps.