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.
This is sadly not working at the moment.
(this is in starterpack)

(set to false automatically)
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)
workspace.gunvalues.l85a2.Value = true
end)
script.Parent.Unequipped:Connect(function()
workspace.gunvalues.l85a2.Value = false
end)
1 Like
Put in your script if script.Parent.Parent == Player.Character then, I think this will help
Which script would that be? (at least 30 characters limit thing)
Put it below game:GetService(“UserInputService”).InputBegan:Connect(function(inputObject, gameProcessedEvent)
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?)
Yes, remember to give end (I must have 30 characters)
I am just testing this (30 word character limit)
Hey this is somewhat unrelated but I am having some problems with my local script inside my tool

(code)
script.Parent.Equipped:Connect(function(Mouse)
script.parent.parent.parent.parent.Lighting.gunvalues.l85a2.Value = true
end)
script.Parent.Unequipped:Connect(function()
script.parent.parent.parent.parent.Lighting.gunvalues.l85a2.Value = false
end)
(code finished)
(output)

Can I know position of script.parent.parent.parent.parent? and what is Lighting, is that a game.Lighting?
I’m Assuming you need to modify the player’s lighting… Lighting is in the game object itself…
“game.Lighting…”
That’s so odd, I’ve never seen lighting pop up. Only workspace, thanks.
it shouldn’t be in workspace… only the game object.
Also: Update,
That piece of code did not seem to change anything. Keybind still does not work when tool is equipped.
Oh, also change inputObject.KeyCode == Enum.KeyCode. to inputObject:IsKeyDown(keyCode) KeyCode | Documentation - Roblox Creator Hub
Unknown global keycode? (30 characters max)
Did you mean it should be implemented like this?
(1) if inputObject:IsKeyDown(KeyCode) == Enum.KeyCode.B and not gameProcessedEvent then
or this
(2) if inputObject:IsKeyDown(KeyCode) and not gameProcessedEvent then
Please check my recent edits to confirm, thanks.
Still is not working. (30 characters)
(code updated)
… = next part missed out (request if you want to see it)
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 script.Parent.Parent == Player.Character then
if inputObject:IsKeyDown(98) and not gameProcessedEvent then
animation(“4853287887”)
if inputObject:IsKeyDown(101) and not gameProcessedEvent then
animation(“4855232288”)
end
end
end
end)
…
(code end)
Oh, wait my bad, sorry for that
if game:GetService("UserInputService"):IsKeyDown(KeyCode) and not gameProcessedEvent then