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

im trying to enable mouse movement in fp when key pressed?

my game is based out of first person and im trying to enable mouse movement in first person when the key m is pressed and after key m is pressed again the mouse will stop movement and beome disabled heres my code

local UserInputService = game:GetService("UserInputService")


while true do
	UserInputService.MouseIconEnabled = false
	
	function onKeyPress(actionName, UserInputState, input0bject)
		if UserInputState == Enum.UserInputState.Begin then
			UserInputService.MouseIconEnabled = true
			UserInputService.ModalEnabled = true
		end
	end
end

game.ContextActionService:BindAction("KeyPress", OnKeyPress, false, Enum.KeyCode.M)

UPDATE: the code is working now but i still cannot enable the movement of my mouse however i now have it when the mouse icon is enable it does not disable it self when clicked or it will not appear when m is pressed?

local UserInputService = game:GetService("UserInputService")
UserInputService.MouseIconEnabled = false
UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.M then
		UserInputService.MouseIconEnabled = true
		--if UserInputService.MouseIconEnabled == true then
			--UserInputService.MouseIconEnabled = false
		end
	end
end)

there is nothing in the output currently?

1 answer

✓ Accepted answer

im just gonna be honest what ever you were doing wasnt gonna ever work ill just give you the code now(local Script)

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.M then
		-- Let mouse move idk how to do that
	end
end)

1 comment

0

dang i was way off everyone i went to said to code it like that, im never asking them for help with code again thats for sure

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