ROBLOX Weapons Kit Causes Issues When Joining Game

I am using a heavily ported/edited version of the ROBLOX-endorsed weapons kit for a new game.

So far it’s been very useful, but there has been an issue that occurs when people join the game.

For starters, the gun kit has been edited in that the third-person/over-the-shoulder camera and cursor lock is toggled only when the gun is equipped… or so I think.

An issue that has been occurring recently with a small but significant amount of testers/players, is the following recording. As you can see, the player is stuck in the lobby/team picking GUI, and cannot do anything about it. Normally, equipping a gun and then unequipping it would help in this situation, but A) that is a pretty low-quality way of solving the issue and B) we have disabled guns in the lobby.

I’ve played around with the camera module a bit, making the following script that is supposed to fire every time a player joins/respawns, to make sure the camera stuff has been fixed, but it doesn’t seem to work 100% of the time, if at all:

local camModule = require(weaponsSystemFolder:WaitForChild("WeaponsSystem"))
client.fixCam.OnClientEvent:Connect(function()
	local char = player.Character or player.CharacterAdded:Wait()
	camModule.camera:setEnabled(false)
	camModule.gui:setEnabled(false)
	camModule.camera.mouseLocked = false
	workspace.CurrentCamera.CameraSubject = char.Humanoid
end)

Does anyone have experience with the gun kit enough to help with this? It’s a pretty sporadic and inconsistent thing where this occurs.

2 Likes


The reason this happens is because of few lines in the ShoulderCamera ModuleScript in the WeaponsSystem

The problematic lines:

-- 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
  1. Replace those lines with this:
-- Hide mouse and lock to center if applicable
if self.mouseLocked and not GuiService:GetEmotesMenuOpen() and not LocalPlayer:GetAttribute("PlayerInMenu") then
	UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
	UserInputService.MouseIconEnabled = false
else
	UserInputService.MouseBehavior = Enum.MouseBehavior.Default
	UserInputService.MouseIconEnabled = true
end

This will check if the player has the PlayerInMenu attribute before locking the mouse.
Now we can use client-server communication via RemoteEvents to give the player the attribute when the mouse should be unlocked, and then remove the attribute when it should be locked.


  1. Create a RemoteEvent in ReplicatedStorage (Create a folder in ReplicatedStorage called “Remotes” first if you haven’t already and then put the RemoteEvent in there)

  1. Put this on the Client when toggling the Team Selection ScreenGui:
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remotes = ReplicatedStorage.Remotes
local goInMenuRemote = remotes.GoInMenu

local player = Players.LocalPlayer
local playerGui = player.PlayerGui

local ScreenGui = playerGui:WaitForChild("teamchoose")
UserInputService.InputBegan:Connect(function(inputObject)
	if inputObject.KeyCode == Enum.KeyCode.E then
		ScreenGui.Enabled = not ScreenGui.Enabled
		goInMenuRemote:FireServer(ScreenGui.Enabled)
	end
end)

NOTE: The important part in that LocalScript is firing the RemoteEvent: goInMenuRemote:FireServer(ScreenGui.Enabled)
If you already have the ScreenGui for Team Selection showing up when you want, you can just take that part and modify the Script in your favor as you desire.


  1. Put this in a Script on the Server:
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local remotes = ReplicatedStorage.Remotes
local goInMenuRemote = remotes.GoInMenu

goInMenuRemote.OnServerEvent:Connect(function(player, state)
	player:SetAttribute("PlayerInMenu", state)
end)

Further reading:

2 Likes

Wow! What a great timing! I’ve had this exact issue with my game. Players (PC) who were on the “select team” screen were basically locked and couldn’t do anything. And I just got it fixed an hour ago!

BaseWeapon ModuleScript, Around line 110 to 122 (I don’t know which line, I have heavily edited the kit myself)

image

if self.instance:IsDescendantOf(workspace) and self.player then
	self:setEquipped(true)
end

^Just comment that out and let me know if your issue persists. (I genuinely have no idea why this is even in the code)

2 Likes

A way to test if it works or not, assuming you have StreamingEnabled on, is to play on 2 different devices at the same time.

Steps to reproduce your bug (you must absolutely do this in order, no matter what):
Player 1 goes out of streaming range from Player 2 (do not equip anything yet!)
Player 1 equips the gun
Player 2 goes in the streaming range of Player 1
Player 2 gets the crosshair gui and gets their mouse locked. (THIS IS THE BUG YOU’RE TRYING TO FIX)

2 Likes

Tried following these steps, I was not able to recreate the glitch.

Going to give this a try, and it looks promising!. The attribute for when players are in the lobby is not necessary, since when players are in the lobby, they are also on the lobby team - I will just go by that.

1 Like

Let me know if it worked and provide further info

1 Like

It somewhat worked.

It still has the GUI and whatnot load in, and once you have selected a team and clicked whatever GUIs that change your attribute to say you’re in the game, it automatically locks your screen like this until you equip and unequip a gun.

I am going to try @R_obotz 's solution and see if that fixes anything.

This ended up being the solution. @GeoSailor 's solution ended up stopping it 90% of the time, but it still persisted. I am still using @GeoSailor 's solution in combination with @R_obotz 's solution, but it seemed like @R_obotz 's solution was what actually got it to stop happening, period.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.