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
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
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
https://developer.roblox.com/en-us/api-reference/class/Animation