Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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)

01--\\ VARIABLES //--
02 
03local player = game.Players.LocalPlayer or  game.Players.PlayerAdded:Wait()
04local character = player.Character or player.CharacterAdded:Wait()
05local humanoid = character:WaitForChild("Humanoid")
06local uis = game:GetService("UserInputService")
07local swing = Instance.new("Animation")
08swing.AnimationId = "rbxassetid://04696235743"
09local debounce = false
10local spin = Instance.new("Animation")
11spin.AnimationId = "rbxassetid://4672766085"
12--\\ SWING //--
13 
14function SwingAtt(inputObject, gameProcessEvent)
15if not debounce then
View all 38 lines...

--\ Damage Script (need help with) //--

01local swing = Enum.KeyCode.E
02local spin = Enum.KeyCode.Q
03local  player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
04local damage = 0
05 
06if player.swing then
07    damage = 15
08 
09    script.Parent.Touched:Connect(function(part1)
10        if part1.Parent:WaitForChild("Humanoid") then
11            part1:TakeDamage(damage)
12        end
13    end)
14end
15 
View all 24 lines...
0
Is there any errors? WN0820 11 — 5y
0
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 EnzoTDZ_YT 275 — 5y
0
No error in the Output or Script Analysis, it's also a normal script inside the tool's handle ANormalPlayer_Alex 11 — 5y
0
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 User#5423 17 — 5y
View all comments (2 more)
0
I'm sorry but I don't know how to do that really, could you maybe help? ANormalPlayer_Alex 11 — 5y
0
I've added the animation script if it helps. ANormalPlayer_Alex 11 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

This might work but at the this bit

1part1.Parent.Humanoid:TakeDamage(damage)

you can just type in...

1part1:TakeDamage(damage)

I hope that this answers your question.

0
I changed it then it said in the output that swing is not a valid member of Player ANormalPlayer_Alex 11 — 5y
0
Are you using a local script? roblox136393 32 — 5y
0
Yes I am ANormalPlayer_Alex 11 — 5y
0
Oh wait are you using game:GetService("UserInputService")? roblox136393 32 — 5y
View all comments (6 more)
0
OMG IM SO STUPID ANormalPlayer_Alex 11 — 5y
0
I've totally forgot about that ANormalPlayer_Alex 11 — 5y
0
No No thats fine I have those moments. roblox136393 32 — 5y
0
Alright so should I make it when the player presses E it changes the damage value to whatever and if a humanoid touches it it takes damage right? ANormalPlayer_Alex 11 — 5y
0
Seems about right. roblox136393 32 — 5y
0
Alright made it work! Thanks dude! ANormalPlayer_Alex 11 — 5y
Ad

Answer this question