Mouse Icon glitching

local mouse = game.Players.LocalPlayer:GetMouse()
local root = script.Parent

function eq()
	mouse.Icon = "rbxassetid://10489343876"
	mouse.Move:Connect(function()
		if root.Equipped then
			if mouse.Target and mouse.Target.Name == "Head" then
				mouse.Icon = "rbxassetid://10489424448"
			else
				mouse.Icon = "rbxassetid://10489343876"
			end
		else
			repeat wait()
				mouse.Icon = 0
			until mouse.Icon == 0
		end
	end)
end

function uneq()
	if root.Unequipped then
		repeat wait()
			mouse.Icon = 0
		until mouse.Icon == 0
	end
end

script.Parent.Activated:Connect(function()
	if mouse.Target ~= nil then
		root.Shoot:FireServer(mouse.Hit,mouse.Target,script.Parent.Handle,script.Parent.Fire)
	end
end)

root.Equipped:Connect(eq)
root.Unequipped:Connect(uneq)

(LocalScript)

Problem: Whenever i unequip the gun tool, the cursor is still the gun crosshair. No errors are printed, can anyone help?

1 Like

instead of setting the mouse.Icon to 0, try setting it to nil.

you are setting it to 0 not “rbxassetid://”
Try this.

game.Players.LocalPlayer:GetMouse().Icon = "rbxassetid://0"

Make sure to mark it as a solution if it helped!

You can’t do that it will error because it’s expecting a mouse icon not “nil”.
It will error this

Unable to assign property Icon. Content expected, got nil
1 Like

Replace:
mouse.Icon = 0
With:
mouse.Icon = ""

A mouse’s ‘Icon’ property expects a ‘Content’ datatype value (similar to string), an empty string (content) reverts the mouse’s icon back to its default. You also need to disconnect the mouse.Move connection.

local mouse = game.Players.LocalPlayer:GetMouse()
local root = script.Parent

local connection

function eq()
	connection = mouse.Move:Connect(function()
		if mouse.Target and mouse.Target.Name == "Head" then
			mouse.Icon = "rbxassetid://10489424448"
		else
			mouse.Icon = "rbxassetid://10489343876"
		end
	end)
	mouse.Icon = "rbxassetid://10489343876"
end

function uneq()
	connection:Disconnect()
	mouse.Icon = ""
end

function acti()
	if mouse.Target then
		root.Shoot:FireServer(mouse.Hit, mouse.Target, root.Handle, root.Fire)
	end
end

root.Equipped:Connect(eq)
root.Unequipped:Connect(uneq)
root.Activated:Connect(acti)
2 Likes