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

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

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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
0
THANK YOU SO MUCH! I really appreat this, if i had more rep points i would up vote you. This its splended ! User#19513 5 — 6y
0
Ay, no problem, Jeter! :) TheRings0fSaturn 28 — 6y
Ad

Answer this question