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

How would I do a on remote event play animation?

Asked by 4 years ago

I'm struggling to do a player and animation that plays when your press a key

P.S. It would also be useful just to know how to play an animation

1 answer

Log in to vote
3
Answered by 4 years ago
Edited 4 years ago
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")

local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character
local Humanoid = Character.Humanoid

 -- Replace with an animation asset of your own.
local AnimationID = '180436334'
local Key = 'k' -- You can change it to another key of your choice.

UserInputService.InputBegan:connect(function(Input, ...)
    if Input.KeyCode == Enum.KeyCode[(Key):upper()] then -- Checks key pressed
        local Anim = Instance.new("Animation") 
        Anim.AnimationId = ("rbxassetid://%s"):format(AnimationID)
        local Track = Humanoid:LoadAnimation(Anim)
        Track:Play() -- Runs animation.
    end
end)

I hope this could help out with you understanding more thoroughly on how to do it. Please take notes of this code and revise on it, and lastly have a merry christmas.

Ad

Answer this question