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?
COMMUNITY QUESTION
How do I make a keydown script to make an animation happen? Also how to do DMG with it?
1 answer
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.
