Is this a problem with PluginMouse?

I am making a basic gun. I am trying to incorporate mouse icons when the gun is equipped/unequipped but its simply not working. I am using the icon assets from the developer hub website: Mouse.Icon (roblox.com) but they do not work. Are they outdated or something? Here are my scripts so far:

(I thought I would try to make a decent gun without raycasting and see how it went. It’s my first non-raycasting gun.)

GunModule Script
local gunModule = {
	pistol = {
		maxAmmo = 10,
		regDamage = 15,
		headshotDamage = 30,
		maxShotDistance = 250,
		shotDebounce = 0.5,
		reloadTime = 1.5,
		gunFireSound = "rbxassetid://6852245478",
		gunReloadSound = "rbxassetid://138084889",
		mouseIcon = "rbxasset://SystemCursors/Cross",
		reloadingIcon = "rbxasset://SystemCursors/Wait"
	}
}

return gunModule


Main Gun Local Script
--//Basic Variables//--
local tool = script.Parent -- getting the tool (gun)
local replicatedStorage = game:GetService("ReplicatedStorage") -- accessing replicated storage
local gunModule = require(replicatedStorage:WaitForChild("GunInfo")) -- getting the gun module script
local handle = tool:WaitForChild("Handle") -- the gun handle
local players = game:GetService("Players") -- players service
local player = players.LocalPlayer -- getting the local player
local gunInModule = gunModule[tool.Name] -- finding the gun in the module script
local reloadTime = gunInModule.reloadTime -- getting the reload time
local debounceTime = gunInModule.shotDebounce -- getting the shot debounce
local maxShotDistance = gunInModule.maxShotDistance -- getting the max shot distance
local maxAmmo = gunInModule.maxAmmo --getting the max ammo
local mouse = player:GetMouse() -- get the player's mouse
local gunEquippedMouseIcon = gunInModule.mouseIcon -- correct equipped mouse icon
local gunGui = tool:WaitForChild("GunGui") --get the gun gui
local playerGui = player:WaitForChild("PlayerGui") -- get the player gui
local displayAmmo = gunGui:WaitForChild("DisplayBullets") -- get the label which displays bullets
local bullets = tool:WaitForChild("Bullets") -- get the bullets values
local reloading = false -- reloading variables
local character = player.Character or player.Character:Wait() -- get the player's character
local humanoidRootPart = character:WaitForChild("HumanoidRootPart") -- get your humanoidRootPart
local objectsToAvoid = { -- a table of all things to not shoot at
	"Baseplate",
	"Terrain",
}
local isShooting = false -- are we shooting? 
local reloadingMouseIcon = gunInModule.reloadingIcon -- reloading mouse icon
local regDamage = gunInModule.regDamage
local headShotDamage = gunInModule.headshotDamage

--//Remote Event//--
local gunFireEvent = tool:WaitForChild("FireGun") -- accessing the remote event

--//Sounds\\--
local gunFireSound = Instance.new("Sound") -- creating a new sound for gun fire
gunFireSound.Name = "GunFireSound" -- setting the sound name
gunFireSound.SoundId = gunInModule.gunFireSound -- setting the soundID
gunFireSound.Parent = tool -- parenting the sound to the tool

local gunReloadSound = Instance.new("Sound") -- creating the reloading sound
gunReloadSound.Name = "GunReloadSound" -- naming the reloading sound
gunReloadSound.SoundId = gunInModule.gunReloadSound -- setting the reload sound ID
gunReloadSound.Parent = tool -- parenting the sound to the tool

--//Functions\\--
local function findTarget(target)
	for _, v in pairs(objectsToAvoid) do
		if v == target.Name then
			return false
		end
	end
	return true
end

local function updateAmmoDisplay() -- this function will update the gun GUI 
	displayAmmo.Text = bullets.Value .. "/" .. maxAmmo -- reset the gun GUI text
end

local function reloadGun() -- this function will run whenever we reload the gun
	if not isShooting then
		reloading = true -- set reloading to true
		
		mouse.Icon = reloadingMouseIcon -- reloading mouse Icon
		
		if gunReloadSound then -- if we have found the correct sound...
			gunReloadSound:Play() -- then we will play it
		end
		bullets.Value = maxAmmo -- reset the number of bullets in the gun
		updateAmmoDisplay() -- update the gun GUI
		
		mouse.Icon = gunEquippedMouseIcon -- reseting the mouse icon to the original mouse icon
		
		reloading = false -- set reloading to false (because we are no longer reloading)
	end	
end

--//Set some variables//--
bullets.Value = 0 -- set bullets to "0" when you first get the gun

--//Services\\--
local userInputService = game:GetService("UserInputService") -- get the user input service

--//Events\\--
tool.Equipped:Connect(function(mouse) -- when the gun is equipped	
	mouse.Icon = gunEquippedMouseIcon
	updateAmmoDisplay() -- update the gun GUI
	gunGui.Parent = playerGui -- parent the gun GUi to the player GUi (show the GUI)
	
	userInputService.InputBegan:Connect(function(input) -- check when a player presses a key
		if bullets.Value < maxAmmo then
			if reloading == false then
				if input.KeyCode == Enum.KeyCode.R then -- if the player presses "R"
					--reload the gun
					reloadGun()
				end
			end
		end
	end)
	mouse.Button1Up:Connect(function() -- when the mouse is clicked
		if not reloading and bullets.Value > 0 then -- if we are not reloading then proceed
			if mouse.Target then -- if there is a valid target then proceed
				isShooting = true --set "isShooting" to true because we are shooting
				if gunFireSound and not gunFireSound.IsPlaying then --play the sound if it is not "nil"
					gunFireSound:Play()
				end
				local target = mouse.Target -- this is the target
				local targetPosition = target.Position -- this is the target position
				local characterPosition = humanoidRootPart.Position  --- this is your humanoidrootpart position
				if targetPosition and characterPosition then -- validate both positions
					local distance = (targetPosition - characterPosition).magnitude -- getting the distance between you and the target
					if distance <= maxShotDistance then --check if you are not too far from the target
						print("It's in range!") 
						local shouldShoot = findTarget(target) --check of you should shoot or not
						if shouldShoot then -- if you can shoot then...
							gunFireEvent:FireServer(target, regDamage, headShotDamage) --check if you should take damage  
                          bullets.Value -= 1
						end
					else
						print("It's not in range!")
					end
				end
				wait(debounceTime) -- wait the debounce time
				
	
				isShooting = false -- set "isShooting" to false because we are not shooting
			end
		elseif not reloading then
			reloadGun()
		end
updateAmmoDisplay()
	end)
end)

tool.Unequipped:Connect(function() --when the gun is unequipped 
	isShooting = false -- set is shooting to false because the gun is unequipped
	reloading = false -- set reloading to false because the gun is unequipped
	mouse.Icon = "" -- reset the mouse icon
	local placedGunGui = playerGui:FindFirstChild("GunGui") -- find the gun GUI in player GUI
	if placedGunGui then -- if we find it, run the code within the "if" statement
		placedGunGui.Parent = tool -- when we find it, parent it to the tool (hide the GUi) 
	end
end)


At first, I thought it was a problem getting string values from the module script, but the sound values (sound variables) work fine, so I cancelled that thought.

replies are thanked, greatly

– Zombo

I can’t see any obvious issues. Is the rest of the gun functioning as usual, or is it just the mouse icon? Are there any errors showing? If not, could you print gunEquippedMouseIcon?

Hm…I do not have any errors as, yes, the rest of the gun is fully operational. I will try to print the gunEquippedMouseIcon.

It prints: “rbxasset://SystemCursors/Cross”

I read another post and I was correct as I thought this only worked with PluginMouse. :frowning:

What do you mean? I’m pretty sure you can change the mouse icon outside of a plugin.

Yes, you can. However OP was trying to change the mouse icon of a player to a system cursor which only works for PluginMouse objects.

2 Likes

Oh, no. I found that you cannot use rbxasset://SystemCursors/Cross for a mouse icon because it is an asset for the PluginMouse.

2 Likes