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

Why doesn't my Animation play when I hit the specific hotkey? (Answered!)

It does not show any output whatsoever

Here's the UPDATED script

local UIS = game:GetService('UserInputService')
local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:wait()

local Key = 'E' --Make sure to capitalize it!

local animation = Instance.new("Animation")
animation.AnimationId = 'rbxassetid://2456539535' --The is the appropriate format

local debounce = true

UIS.InputBegan:Connect(function(Input, IsTyping)
 if IsTyping then return end
 local KeyPressed = Input.KeyCode
 if KeyPressed == Enum.KeyCode[Key]and debounce then
    debounce = false
    local LoadAnimation = Char.Humanoid:LoadAnimation("Animation")
    LoadAnimation:Play()
    wait(2)
    debounce = true
 end
end)

5 comments

0

Try changing 'e' to a capital

0

Line 8, the correct formatting should be something like: “rbxassetid://2456539535".

0

Sorry to all,my mistake.It says 'AnimationID is not a valid member of animation'

0

Forget that,just a little typo.Its supposed to be AnimationId.Anyways they say there's an error on line 17 They don't tell me whats wrong

0

Nevermind,I got it all sorted thanks for the help all!

2 answers

✓ Accepted answer

Alright, so I have spotted two issues with the script.

On line 5, you are calling Key to be equal to 'e'. However, as far as I'm aware, UIS keycodes go by the capital letter, so just make a mental note to be aware of that.

As well as that, on line 8, the formatting for the animation is incorrect. Roblox's format this is rbxassetid://[InsertCodeHere]. So it should be replaced with rbxassetid://2456539535.

local UIS = game:GetService('UserInputService')
local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:wait()

local Key = 'E' --Make sure to capitalize it!

local animation = Instance.new("Animation")
animation.AnimationID = 'rbxassetid://2456539535' --The is the appropriate format

local Debounce = true

UIS.InputBegan:Connect(function(Input, IsTyping)
 if IsTyping then return end
 local KeyPressed = Input.KeyCode
 if KeyPressed == Enum.KeyCode[Key]and debounce then
    Debounce = false
    local LoadAnimation =Char.Humanoid:LoadAnimation(Animation)
    LoadAnimation:Play()
    wait(2)
    Debounce = true
 end
end)

All in all, just make sure you have that E capitalized and have the right format for animations. (That format is the same for decals, images, etc.)

1 comment

0

You kinda helped me with the coding so here's a reward ^-^

Your error on line 15 after "debounce" you missed "true", so type this on that line

if KeyPressed == Enum.KeyCode[Key]and debounce == true then

10 comments

0

It still doesn't work.Is my link to the animation wrong??

0

idk. Your script is correct, so maybe yes

0

Try to change animationid only numbers

0

Ok

0

sadly it doesn't work

0

I have one more idea. On line 8 "Animation.AnimationId" change to "animation.AnimationId"

0

I think that might work but I'll try it tomorrow

0

k k

0

Debounce and debounce == true are identical if in an if statement.

0

ok

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