function DynamicThumbstick.GetIsJumping(k)local w=k.isJumping k.isJumping=false return w end function DynamicThumbstick.EnableAutoJump(w,k)local u=Players.LocalPlayer.Character and Players.LocalPlayer.Character:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")if u then if k then w.shouldRevertAutoJumpOnDisable=u.AutoJumpEnabled==false and Players.LocalPlayer.DevTouchMovementMode==Enum.DevTouchMovementMode.UserChoice u.AutoJumpEnabled=true elseif w.shouldRevertAutoJumpOnDisable then u.AutoJumpEnabled=false end end end function DynamicThumbstick.Enable(u,k,w)if k==nil then return false end k=k and true or false if u.enabled==k then return true end if k then if not u.thumbstickFrame then u:Create(w)end if Players.LocalPlayer.Character then u:OnCharacterAdded(Players.LocalPlayer.Character)else Players.LocalPlayer.CharacterAdded:Connect(function(k)u:OnCharacterAdded(k)end)end else u:OnInputEnded()end u.enabled=k u.thumbstickFrame.Visible=k end function DynamicThumbstick.OnCharacterAdded(w,k)for k,u in ipairs(k:GetChildren())do if u:IsA("\084\111\111\108")then w.toolEquipped=u end end k.ChildAdded:Connect(function(k)if k:IsA("\084\111\111\108")then w.toolEquipped=k elseif k:IsA("\072\117\109\097\110\111\105\100")then w:EnableAutoJump(true)end end)k.ChildRemoved:Connect(function(k)if k==w.toolEquipped then w.toolEquipped=nil end end)w.humanoid=k:FindFirstChildOfClass("\072\117\109\097\110\111\105\100")if w.humanoid then w:EnableAutoJump(true)end end
-- Note: Overrides base class GetIsJumping with get-and-clear behavior to do a single jump
-- rather than sustained jumping. This is only to preserve the current behavior through the refactor.
function DynamicThumbstick:GetIsJumping()
	local wasJumping = self.isJumping
	self.isJumping = false
	return wasJumping
end

function DynamicThumbstick:EnableAutoJump(enable)
	local humanoid = Players.LocalPlayer.Character and Players.LocalPlayer.Character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		if enable then
			self.shouldRevertAutoJumpOnDisable = (humanoid.AutoJumpEnabled == false)
				and (Players.LocalPlayer.DevTouchMovementMode == Enum.DevTouchMovementMode.UserChoice)
			humanoid.AutoJumpEnabled = true
		elseif self.shouldRevertAutoJumpOnDisable then
			humanoid.AutoJumpEnabled = false
		end
	end
end

function DynamicThumbstick:Enable(enable, uiParentFrame)
	if enable == nil then
		return false
	end -- If nil, return false (invalid argument)
	enable = enable and true or false -- Force anything non-nil to boolean before comparison
	if self.enabled == enable then
		return true
	end -- If no state change, return true indicating already in requested state

	if enable then
		-- Enable
		if not self.thumbstickFrame then
			self:Create(uiParentFrame)
		end

		if Players.LocalPlayer.Character then
			self:OnCharacterAdded(Players.LocalPlayer.Character)
		else
			Players.LocalPlayer.CharacterAdded:Connect(function(char)
				self:OnCharacterAdded(char)
			end)
		end
	else
		-- Disable
		self:OnInputEnded() -- Cleanup
	end

	self.enabled = enable
	self.thumbstickFrame.Visible = enable
end

function DynamicThumbstick:OnCharacterAdded(char)
	for _, child in ipairs(char:GetChildren()) do
		if child:IsA("Tool") then
			self.toolEquipped = child
		end
	end

	char.ChildAdded:Connect(function(child)
		if child:IsA("Tool") then
			self.toolEquipped = child
		elseif child:IsA("Humanoid") then
			self:EnableAutoJump(true)
		end
	end)
	char.ChildRemoved:Connect(function(child)
		if child == self.toolEquipped then
			self.toolEquipped = nil
		end
	end)

	self.humanoid = char:FindFirstChildOfClass("Humanoid")
	if self.humanoid then
		self:EnableAutoJump(true)
	end
end
