Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
1
Answered by 5 years ago

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)
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 skillfulzombie88 28 — 5y
Ad

Answer this question