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 4 years ago
Edited 4 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)

--\\ 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

0
Is there any errors? WN0820 11 — 4y
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 — 4y
0
No error in the Output or Script Analysis, it's also a normal script inside the tool's handle ANormalPlayer_Alex 11 — 4y
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 — 4y
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 — 4y
0
I've added the animation script if it helps. ANormalPlayer_Alex 11 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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.

0
I changed it then it said in the output that swing is not a valid member of Player ANormalPlayer_Alex 11 — 4y
0
Are you using a local script? roblox136393 32 — 4y
0
Yes I am ANormalPlayer_Alex 11 — 4y
0
Oh wait are you using game:GetService("UserInputService")? roblox136393 32 — 4y
View all comments (6 more)
0
OMG IM SO STUPID ANormalPlayer_Alex 11 — 4y
0
I've totally forgot about that ANormalPlayer_Alex 11 — 4y
0
No No thats fine I have those moments. roblox136393 32 — 4y
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 — 4y
0
Seems about right. roblox136393 32 — 4y
0
Alright made it work! Thanks dude! ANormalPlayer_Alex 11 — 4y
Ad

Answer this question