Keybind script not working

I’ve been trying to get this animation to play when I press E, but for some reason it’s not working. Tried searching up yt vids about keybinds but the scripts look the same, please help. This is the code

local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local store = game:GetService("ServerStorage")
local enabled = true
local karsQ = store.KarsAnim.KarsBarrage

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.E and enabled == true then
		enabled = false
		local char = game.Workspace:WaitForChild(player.Name)
		local h = char:WaitForChild("Humanoid")
		local x = h:LoadAnimation(karsQ)
		x:Play()
		wait(2)
		enabled = true
	end
end)

The reason why the script isn’t working is because you’re trying to get ServerStorage. Remove that line and you’re fine. The client can’t get ServerStorage because Roblox made it always hidden to the client. However, ServerScripts are able to get the services ServerStorage and ServerScriptService.

there’s two arguments in InputBegan, “Input” and “GameProcessed”. you have to use two arguments in that order, because you used the GameProcessed argument instead of input.

Oh, I’ll try find a way to workaround this ty

What?!?!

Just remove the line game:GetService("ServerStorage")

I have my animations in server storage

You’re wrong on this. It goes InputBegan:Connect(function(InputObject,GameProcessedEvent)

You can’t get server storage at all. Just parent them to replicated storage.

Oh, my mistake! (30 character limit)

weird it still doesn’t work and I’m not getting any errors in output

you have to use two arguments in the function, “Input” and “GameProcessed” in that order. You’re using the gameprocessed argument instead of the input.

There might be 5 things you’ve done wrong

  1. You didn’t listen to what I said

  2. There’s a long yield that’s not in a coroutine.wrap()

  3. Enabled is changed to false

  4. You’re still trying to get ServerStorage on the client

  5. You’re using this code on a Server Script

  6. store.KarsAnim.KarsBarrage can’t be found.

:smirk: im unfunny

He’s not. Stop giving him wrong information.

Just to eliminate any confusion, the correct order of parameters for UserInputService.InputBegan is

UserInputService.InputBegan:Connect(function(inputObject, gameProcessed)

This is stated on the wiki as well.

Him omitting gameProcessed does not change anything; however, he may want to utilize the usefulness of that parameter.

2 Likes

It’s not wrong, I’ve done this mistake.

i think it might be a long yield

I think you’re using this code on a server script (4)

it’s a local script I’ve checked that

Enabled may be false or the script is disabled