Hello all! I'm having an issue with a script I'm making.. To give you some insight, I want it when I press "LeftShift" it plays an animation, BUT it needs to check if the tool is equipped(M4), if the tool isn't equipped, then when you press Left Shift nothing happens. This is a Local Script inside of StarterCharacterScripts
:
local player = game.Players.LocalPlayer local character = player.Character or script.Parent local Humanoid = character.Humanoid local tool = game.StarterPack.M4 local UserInputService = game:GetService('UserInputService') local AnimationID = 'rbxassetid://033456263' local Key = "LeftShift" UserInputService.InputBegan:Connect(function(Input, IsTyping) if IsTyping then return end if Input.KeyCode == Enum.KeyCode[Key] then local Animation = Instance.new("Animation") Animation.AnimationId = AnimationID local LoadAnimation = Humanoid:LoadAnimation(Animation) tool.Equipped:Connect(function() LoadAnimation:Play() end) end end)
Hello, so what you should've done was added the equipped event first then after the player presses the key the animation will play. I hope this was what you were looking for :D
--[[ Script ]] local player = game.Players.LocalPlayer local character = player.Character or script.Parent local Humanoid = character.Humanoid local tool = game.StarterPack.M4 local UserInputService = game:GetService('UserInputService') local AnimationID = 'rbxassetid://033456263'
tool.Equipped:Connect(function() local Key = "LeftShift" UserInputService.InputBegan:Connect(function(Input, IsTyping) if IsTyping then return end if Input.KeyCode == Enum.KeyCode[Key] then local Animation = Instance.new("Animation") Animation.AnimationId = AnimationID local LoadAnimation = Humanoid:LoadAnimation(Animation) LoadAnimation:Play() end end) end)