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

How would i go about adding a animation ID to a gun script?

I am having trouble finding a spot to place a animation ID. When i place it any where the gun either fires one round and frezzes, or the animation ID that is place does nothing. The animation is going to be character movement. How would I tell the script to play animation when "R" is pressed and when gun is firing play recoil animation. Note this is not a request I just need a VALID answer.

1 answer

✓ Accepted answer

This requires you to use the UserInputService.

Also, to use an animation, you'll have to create it yourself, as ROBLOX blocks access to other people's animations for whatever reason.

Here's a small bit of code to help you get started.

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

local animTrack = nil

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.R then
		animTrack = player.Humanoid:LoadAnimation(animation)
		print("R was pressed") --You'll want to put your code here
		animTrack:Play()
	end
end

2 comments

0

THANK YOU SO MUCH! I really appreat this, if i had more rep points i would up vote you. This its splended !

0

Ay, no problem, Jeter! :)

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