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

1-- Hide mouse and lock to center if applicable
2if self.mouseLocked and not GuiService:GetEmotesMenuOpen() then
3    UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
4    UserInputService.MouseIconEnabled = false
5else
6    UserInputService.MouseBehavior = Enum.MouseBehavior.Default
7    UserInputService.MouseIconEnabled = true
8end

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:

01local UIS = game:GetService(“UserInputService”) -- Gets the UserInputService
02 
03while wait() do -- loop this
04if UIS:IsKeyDown(Enum.KeyCode.Q) == true then -- If Q is being held down then
05      UIS.MouseBehavior = Enum.MouseBehavior.Default
06      UIS.MouseIconEnabled = true
07      -- Fix mouse
08else
09      UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
10      UIS.MouseIconEnabled = false
11      -- Revert mouse back to normal
12end
13end
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:

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

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

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

And when the GUI is gone, use this:

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

Hope this helped!

Answer this question