Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i make a moving detect?

How do i detect the play is moving? I can't found any detect code i want. And someone said i can't place a function in function. Then how do i do? These is my codes:

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.LeftControl then
		KeyHolding = true
		SquatStart:play()
		wait(SquatStart.Length)
		while KeyHolding do
			--if Detect Moving then
			----SquatMoving:play()
			----wait(SquatMoving.Length)
			--else
			----Squating:play()
			----wait(Squating.Length)
		end
	end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

Thanks everyone!

3 comments

0

You can put a function inside a function. Who said that you cannot?

0

Omg Really :O? i'll try it, thanks!

0

No can't do it. I wanna code detect in the "Detect Moving"

1 answer

✓ Accepted answer

Well to detect if a player is moving, you simply can use InputBegan and simply detect if the input key is w a s or d

local plr = game.Players.LocalPlayer
local UIS = game:GetService('UserInputService')

UIS.InputBegan:Connect(function(input, IsTyping)
	if IsTyping then return end
	local KeyPressed = input.KeyCode
	if KeyPressed == Enum.KeyCode.W or KeyPressed == Enum.KeyCode.A or KeyPressed == Enum.KeyCode.S or KeyPressed == Enum.KeyCode.D then
		print('Player Is Moving')
	end
end)

Hopefully this helped you.

3 comments

0

Then when i hold these key already?

0

If you hold keys it's still input began.

0

Ohhh kay! I'll try it.

This discussion is preserved as it was. New answers, comments, and votes are closed.