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)
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.
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.