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 |
2 | if self.mouseLocked and not GuiService:GetEmotesMenuOpen() then |
3 | UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter |
4 | UserInputService.MouseIconEnabled = false |
5 | else |
6 | UserInputService.MouseBehavior = Enum.MouseBehavior.Default |
7 | UserInputService.MouseIconEnabled = true |
8 | end |
is there a way to enable the mouse to perhaps a key being held?
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:
01 | local UIS = game:GetService(“UserInputService”) -- Gets the UserInputService |
02 |
03 | while wait() do -- loop this |
04 | if 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 |
08 | else |
09 | UIS.MouseBehavior = Enum.MouseBehavior.LockCenter |
10 | UIS.MouseIconEnabled = false |
11 | -- Revert mouse back to normal |
12 | end |
13 | end |
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:
1 | UserInputService.MouseBehavior = Enum.MouseBehavior.Default |
2 | UserInputService.MouseIconEnabled = true |
So, my solution for this is that whenever there is a GUI use this:
1 | UserInputService.MouseBehavior = Enum.MouseBehavior.Default |
2 | UserInputService.MouseIconEnabled = true |
And when the GUI is gone, use this:
1 | UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter |
2 | UserInputService.MouseIconEnabled = false |
Hope this helped!