Hold down key to block works in studio but not online

I have a script that makes you block as long as you have the “X” key held down using userinputservice, it works fine in studio, even in a local server hosted in studio, but not online. Basically my arms don’t go down after the HoldBlock played. The “Block” animation makes the arms go up and the “HoldBlock” makes them keep up.

function IsHeld()

HoldBlock:Play()

end

UserInputService.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.X then
Block:Play()
blockEvent:FireServer(true)
IsHeld()
end

end)

UserInputService.InputEnded:connect(function(input, inputProcessed)
if inputProcessed == false and input.KeyCode == Enum.KeyCode.X then

    HoldBlock:Stop()
	blockEvent:FireServer(false)
	Block:Play(0.100000001,1,-1)
end

end)

(I don’t know how to paste the code properly, sorry)

1 Like

Ask your self these questions first.

Have I published the game?

Have I saved changes?

That being done, let’s focus onto your script. You are using deprecated functions, and are using global functions.

Use local functions, and don’t use deprecated functions. Local functions are much faster than global functions, are good for scopes and organization.

Here is your script. Basically, I made it more efficient and better.

local function IsHeld()

HoldBlock:Play()
end

UserInputService.InputBegan:Connect(function(input, inputProcessed)

if input.KeyCode == Enum.KeyCode.X and inputProcessed then
Block:Play()
blockEvent:FireServer(true)
IsHeld()
      end
end)

UserInputService.InputEnded:Connect(function(input, inputProcessed)

if  input.KeyCode == Enum.KeyCode.X and not inputProcessed and then -- This line is a conditional and it won't execute the other lines unless it's satisfied.

    Held:Disconnect() -- Why not disconnect the function when does the same thing?
	blockEvent:FireServer(false)
	Block:Play(0.100000001,1,-1)
        end
end)

I appreciate your help, I made sure to save the changes and publish them, and even though I’m using your script the animation still doesn’t stop after the input ends.

Add a print statement after the if statement.

if input.KeyCode == Enum.KeyCode.X and not inputProcessed and then
print(“True”)

Does it print true?

Yes it does, as I said it’s working fine in studio. There’s just something wrong when going on a online server that I can’t figure out.

Make sure that this is turned off.

image

If it is, make sure you commit your scripts. I don’t really find the issue…

Team create is off so that’s out the window, I guess I’ll have to look in my scripts, though I have no idea what would work in studio and not online.

Nothing is wrong with your script, do you check developer console when in the actual game?

Double check HoldBlock is a looping animation with the highest priority.

Is the animation your own? Is this game on your account or a group? And how long ago did you create the animation?

I checked everything, it’s my animation, on my game, the animation was made yesterday. Everything should work fine, I swear this is black magic.

is filtering enabled on in the test place?

1 Like

I believe filtering enabled is on by default, I never disabled it and I don’t even think there’s a way to do it anymore.

Alright I took the bit of code and pasted it in a empty baseplate, turns out this script part works fine. The problem seemingly comes from another script, I’ll look into it.