Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make a fighting script for R15 which plays a animation when you press a key?

Hello i been looking every where to find out where i can look for help on how to script a hand to hand combat script that plays a animation when rather clicked or key pressed if you can help me that would be great!

1 answer

First of all, use UserInputServicelink to listen for key events, then using Animationslink load it into the character

example -- should work as a local script in StarterPack. Remember that the character is destroyed when you re-spawn too

local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
    character = player.CharacterAdded:wait()
end


local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=144884906"

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.R then
		local animTrack = character.Humanoid:LoadAnimation(animation)
		animTrack:Play()
	end
end
 
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

This discussion is preserved as it was. New answers, comments, and votes are closed.