Still have questions? Join our Discord server and get real time help.
1

# I am working on a dash script, I was wondering how animations work?

I've been trying to call an animation I made, and I have no idea how to do it. I checked the wiki and could not find ANY code on it. Does anybody know how to call/play an animation when a button is pressed?


I have this so far

local UserInputService = game:GetService("UserInputService")

local function onInputBegan(input,gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
local keyPressed = input.KeyCode
if keyPressed == "Shift" then
--animation
end
end
end

UserInputService.InputBegan:connect(onInputBegan)


1
Astralyst 384
11 months ago
Edited 11 months ago

Please don't forget to define player.

• make sure script is a localscript
local player = game.Players.LocalPlayer


If there is already an animation file, or whatever you call it; you can do this.

if player.Character then -- to check if character exists
local run = player.Character.Humanoid:LoadAnimation(// where the animation is) -- for example, "script.Run", you should get the idea if you know the fundamentals.
wait()
run:Play()
player.Character.Humanoid.WalkSpeed = // walkspeed


for inputEnded, you can do the same; but the opposite.

player.Character.Humanoid.WalkSpeed = // walkspeed
wait()
run:Stop()


you can also make it a global variable (by removing the "local" on "local run", line 2), but I'm not sure which one would work, haven't tested this script myself.

If there isn't an animation file, create an instance by;

local run = instance.new("Animation")
run.AnimationId = '// animation id'
wait()
playRun:Play()

0
also; make sure the animation is owned by you, or else it won't work and it'll send you an error saying "insufficient permission" or "unauthorized" or whatsoever, it just won't work if you don't own the animation. Astralyst 384 — 11mo
1
Edited 11 months ago

if you have something without a Humanoid then use AnimationController instead and AnimationController can be used from a Script or a LocalScript

-- With a Humanoid
-- LOCALSCRIPT
local Players = game:GetService"Players"
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild"Humanoid"

local function PlayAnimation()
local Animation = Instance.new"Animation" -- if you haven't inserted one already
Animation.AnimationId = "rbxassetid://1234567" -- Example animation id