Key press and release to tween not being responsive

I have a part in this LocalScript where when WASD or mouse1 is pressed, it will squish the player character’s custom mesh, and when the key is released, it will go back to its normal proportions. However, it seems to be very unresponsive if the player tries to spam the keys, and only works if the player clicks and releases slowly.

Section of LocalScript

local squishTween = tweenService:Create(playerMesh, squishTweenInfo, {Size = Vector3.new(playerMesh.Size.X + 0.5, playerMesh.Size.Y - 3, playerMesh.Size.Z)})
local unsquishTween = tweenService:Create(playerMesh, squishTweenInfo, {Size = Vector3.new(playerMesh.Size.X, playerMesh.Size.Y, playerMesh.Size.Z)})

function keyDownSquish(mode: boolean)
	if mode then
		unsquishTween:Cancel()
		squishTween:Play()
	elseif not mode then
		squishTween:Cancel()
		unsquishTween:Play()
	end
end

mouse.Button1Down:Connect(function()
	if not userInputService.KeyboardEnabled then return end

	keyDownSquish(true)
end)

mouse.Button1Up:Connect(function()
	if not userInputService.KeyboardEnabled then return end

	keyDownSquish(false)
end)
2 Likes

The tweens are getting canceled and played too fast when keys are pressed repeatedly. You could add a short delay between key presses to prevent spamming, or make sure tweens don’t overlap by adding a debounce.