Stop Auto Farm On Movement

Hi guys, do you know how to change a value when the player starts moving BY INPUT?. Example, many games do have this feature where if you start moving by input the auto farm stops.
Thanks in advance!

2 Likes

Use UserInputService.InputBegan to detect some movement.

UserInputService.InputBegan:Connect(function(input)

end)

Then check the input type to see if it’s WASD:

UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.Keycode.W or input.KeyCode == Enum.Keycode.A or input.KeyCode == Enum.Keycode.S or input.KeyCode == Enum.Keycode.D then
-- stop auto farming
end)

OR you could check using Humanoid.MoveDirection like so:
(This is the better method)

if Humanoid.MoveDirection > 0 then
-- stop auto farming
end
2 Likes

But what if the player is on mobile, i would have to check the mobile input too. Also, wouldn’t using MoveDirection be wrong? Since auto farming works by auto walking to a point (I’ve made it using :MoveTo()), it’ll always be greater than 0?

2 Likes

something like this? The function shouldn’t get executed by :MoveTo()

My answer doesn't work because PlayerActions aren't universal and are only exclusive to computer for some reason
local ContextActionService = game:GetService("ContextActionService")

local function playerInput(_, inputState, inputObject)
	if inputState ~= Enum.UserInputState.Begin then
		return
	end
	
	print("player pressed something to move")
end

local actions = Enum.PlayerActions:GetEnumItems()
for i, action in actions do
	ContextActionService:BindAction("characterStuff" .. i, playerInput, false, action)
end
1 Like

Then include checks for mobile users too…?
Use UserInputService (you’ll need to check the UserInputService.TouchEnabled to check if the user is on mobile)
And you’ll probably have to modify default roblox controls to get the signal from player movement actions on mobile (on pc just bind to keys like he mentioned, much easier)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.