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

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

Asked by 4 years ago
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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

(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!

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
0
wait when you tested it did you do Animation.AnimationId = 'rbxassetid://4957376200' GlxkTerrence 5 — 4y

Answer this question