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

How do I make a keydown script to make an animation happen? Also how to do DMG with it?

Asked by 9 years ago

I am trying to make a keydown script so when I press q a certain animation happens which is a punch so I can do it in my game, also how would I make the punch do dmg for each hit?

1 answer

Log in to vote
0
Answered by 9 years ago

Well, to start off don't use Mouse.KeyDown, use UserInputService.InputBegan. It is more efficient. Here you go:

local plr = game.Players.LocalPlayer
local UIS = game:GetService('UserInputService')
local AnimationId = 0 --PUT THE ID OF THE ANIMATION HERE
local Animation = Instance.new("Animation",script)
Animation.AnimationId = "rbxassetid://"..AnimationId
local dmg = 10 -- THE DAMAGE THE PUNCH DEALS
Animation.Name = "Punch"
local DamageFunction = Player:WaitForChild("Character")["Right Arm"].Touched:connect(function(p)
    if p.Parent:FindFirstChild("Humanoid") then
        p.Parent.Humanoid:TakeDamage(dmg)
    end
end)
DamageFunction:disconnect()
UIS.InputBegan:connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.Q then
        local Anim = Player.Character.Humanoid:LoadAnimation(Animation)
        Anim:Play()
        DamageFunction:connect()
        wait(2)
        Anim:Stop()
        DamageFunction:disconnect()
    end
end)

There may be some few minor errors.

Ad

Answer this question