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

Trying to bind a certain key to an animation but it wont work?

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

local Key got 'Shift'

local Animation = Instance.new("Animation")
Animation.AnimationId = 'rbxassetid://4957376200'

UIS.InputBegan:Connect(function(Input, IsTyping)
	if IsTyiping then return end 
	local KeyPressed = Input.Keycode
	if KeyPressed == Enum.KeyCode[Key] then 
		print (plr.Name..'  has pressed  '..Key)
	local Load.Animation = Char.Humanoid:LoadAnimation(Animation)
	LoadAnimation:Play()
	
end)

Can somebody please help me?

2 answers

✓ Accepted answer

(assuming this is a local script)

Your script looks fine, the only problem I see is:

local Key got 'Shift'

There are two problems. First, I have no clue what "got" is, try to use "=". Second, You just used "Shift" and you didn't define whether "Shift" meant "LeftShift" or "RightShift". I'm assuming you meant left.

With that being said, here is the new code:

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

local Key = 'LeftShift'

local Animation = Instance.new("Animation")
Animation.AnimationId = 'rbxassetid://4957376200'

UIS.InputBegan:Connect(function(Input, IsTyping)
    if IsTyping then return end 
    local KeyPressed = Input.Keycode
    if KeyPressed == Enum.KeyCode[Key] then 
    print (plr.Name..'  has pressed  '..Key)
    local LoadAnimation = Char.Humanoid:LoadAnimation(Animation)
    LoadAnimation:Play()
end)

p.s remember to accept answer if it solved your issue!

There was many spelling errors and things missing. I fixed the script and put an animation inside the script for this to work. Make sure the actual animation has the Id. Here's how it's supposed to look: https://imgur.com/a/WnicZrJ

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

local Key = 'LeftShift'

local Animation = script.Animation

UIS.InputBegan:Connect(function(Input, IsTyping)
    if IsTyping then return end 
    local KeyPressed = Input.KeyCode
    if KeyPressed == Enum.KeyCode[Key] then 
        print (plr.Name..'  has pressed  '..Key)
    	local AnimationTrack = Char.Humanoid:LoadAnimation(Animation)
    	AnimationTrack:Play()
	end
end)

1 comment

0

wait when you tested it did you do Animation.AnimationId = 'rbxassetid://4957376200'

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