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
This might work but at the this bit
part1.Parent.Humanoid:TakeDamage(damage)
you can just type in...
part1:TakeDamage(damage)
I hope that this answers your question.