I’m trying to make it so when I equip a tool it allows the player to press a keybind on their keyboard to play an animation, when the player is not equipping the key these keybinds will not work.
local Player = game.Players.LocalPlayer
local Character = Player.Character
local CharAnimation
while true do
wait (0.5)
if script.parent.parent.parent.parent.Lighting.gunvalues.l85a2 == true then
game:GetService(“UserInputService”).InputBegan:Connect(function(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.B and not gameProcessedEvent then
animation(“4853287887”)
elseif inputObject.KeyCode == Enum.KeyCode.E and not gameProcessedEvent then
animation(“4855232288”)
end
end)
function animation(AnimationID)
if Character then
local UseLessAnimation = Character:FindFirstChild(“AnimationCharacter”)
if CharAnimation then
CharAnimation:Stop()
end
if UseLessAnimation then
if UseLessAnimation.AnimationId == “rbxassetid://”…AnimationID then
UseLessAnimation:Destroy()
return
end
UseLessAnimation:Destroy()
end
local Animation =Instance.new(“Animation”,Character)
Animation.Name= “AnimationCharacter”
Animation.AnimationId = “rbxassetid://”…AnimationID
CharAnimation= Character.Humanoid:LoadAnimation(Animation)
CharAnimation:Play()
else if script.parent.parent.parent.parent.Lighting.gunvalues.l85a2 == false then
wait (2)
end
end
end
end
end (this script is in StarterGui)
I’m unable to find out why this is not working, would anybody please be able to help me? (I also am trying to make it so that people can see the animation server side)
This is the code inside the local script inside the tool
script.Parent.Equipped:Connect(function(Mouse)
if script.parent.parent.parent.parent.Lighting.gunvalues.l85a2 == true then
game:GetService(“UserInputService”).InputBegan:Connect(function(inputObject, gameProcessedEvent)
if script.Parent.Parent == Player.Character then
if inputObject.KeyCode == Enum.KeyCode.B and not gameProcessedEvent then
animation(“4853287887”)
…
(like this?)