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

Enable mouse with weapons kit?

Asked by 4 years ago

Hi I want to use the weapons kit from the developer website, however once i have installed them into my game the mouse disappears and the camera is locked which is great for gameplay but i would like to be able to enable the mouse at certain points to use Gui's.

anyone know how to do this?

I have looked at the scripting within the pack and i think it would be something to do with the shouldercam script as there is a part which says

    -- Hide mouse and lock to center if applicable
    if self.mouseLocked and not GuiService:GetEmotesMenuOpen() then
        UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
        UserInputService.MouseIconEnabled = false
    else
        UserInputService.MouseBehavior = Enum.MouseBehavior.Default
        UserInputService.MouseIconEnabled = true
    end

is there a way to enable the mouse to perhaps a key being held?

0
I just wouldn't use the kit to begin with. You should be able to make your own guns, therefore you know how the code works. Nckripted 580 — 4y

2 answers

Log in to vote
-1
Answered by
OhManXDXD 445 Moderation Voter
4 years ago
Edited 4 years ago

Yeah sure, you can undo the mouse if a key is pressed using UserInputService. Actually, the script uses UserInputService itself.

Read about it here: [https://developer.roblox.com/en-us/api-reference/class/UserInputService]

Anyways, let me show you how you would do this.

Let’s say if you’re holding down the key Q, the mouse would be unlocked. Make a new LocalScript in the pack and put this:

local UIS = game:GetService(“UserInputService”) -- Gets the UserInputService

while wait() do -- loop this
if UIS:IsKeyDown(Enum.KeyCode.Q) == true then -- If Q is being held down then
      UIS.MouseBehavior = Enum.MouseBehavior.Default
      UIS.MouseIconEnabled = true
      -- Fix mouse
else
      UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
      UIS.MouseIconEnabled = false
      -- Revert mouse back to normal
end
end
0
You should change my quotation marks because my keyboard isn’t doing them correctly OhManXDXD 445 — 4y
0
This example is very expensive, and I would use the InputBegan event instead. Nckripted 580 — 4y
0
-1 for using an idiom instead of the appropriate event DeceptiveCaster 3761 — 4y
Ad
Log in to vote
0
Answered by
Nckripted 580 Moderation Voter
4 years ago

I hope you listened to my comment. However, if you want to stick with the guns (and I see no reason why shouldn't, if these guns have everything you need), I would focus on the following lines:

UserInputService.MouseBehavior = Enum.MouseBehavior.Default
UserInputService.MouseIconEnabled = true

So, my solution for this is that whenever there is a GUI use this:

UserInputService.MouseBehavior = Enum.MouseBehavior.Default
UserInputService.MouseIconEnabled = true

And when the GUI is gone, use this:

UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
UserInputService.MouseIconEnabled = false

Hope this helped!

Answer this question