Press key to damage humanoid? [ANSWERED]
Asked by
5 years ago Edited 5 years ago
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)
03 | local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait() |
04 | local character = player.Character or player.CharacterAdded:Wait() |
05 | local humanoid = character:WaitForChild( "Humanoid" ) |
06 | local uis = game:GetService( "UserInputService" ) |
07 | local swing = Instance.new( "Animation" ) |
10 | local spin = Instance.new( "Animation" ) |
14 | function SwingAtt(inputObject, gameProcessEvent) |
16 | if inputObject.KeyCode = = Enum.KeyCode.E then |
18 | humanoid:LoadAnimation(swing):Play() |
24 | uis.InputBegan:Connect(SwingAtt) |
28 | function SpinAtt(inputObject, gameProcessEvent) |
30 | if inputObject.KeyCode = = Enum.KeyCode.Q then |
32 | humanoid:LoadAnimation(spin):Play() |
38 | uis.InputBegan:Connect(SpinAtt) |
--\ Damage Script (need help with) //--
01 | local swing = Enum.KeyCode.E |
02 | local spin = Enum.KeyCode.Q |
03 | local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait() |
09 | script.Parent.Touched:Connect( function (part 1 ) |
10 | if part 1. Parent:WaitForChild( "Humanoid" ) then |
11 | part 1 :TakeDamage(damage) |
19 | script.Parent.Touched:Connect( function (part 2 ) |
20 | if part 2. Parent:WaitForChild( "Humanoid" ) then |
21 | part 2. Parent.Humanoid:TakeDamage(damage) |