Mouse icon keeps going back to normal

i’m using a custom mouse icon in my game

this is currently my code:

local rs = game:GetService("RunService")
local uis = game:GetService("UserInputService")
local storage = game:GetService("ReplicatedStorage")

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

local dayevent = storage:WaitForChild("dayevent")

local id = "rbxasset://textures/Cursors/KeyboardMouse/ArrowFarCursor.png"
local id2 = "rbxasset://textures/Cursors/KeyboardMouse/ArrowCursor.png"

local normal = "rbxassetid://13902810543"
local far = "rbxassetid://13902812046"

task.defer(function()
	mouse.Icon = normal
	uis.MouseIcon = normal
end)

uis.Changed:Connect(function(prop)
	if prop == "MouseIcon" then
		if uis.MouseIcon == id then
			mouse.Icon = normal
			uis.MouseIcon = normal
		elseif uis.MouseIcon == id2 then
			mouse.Icon = far
			uis.MouseIcon = far
		end
	end
end)

dayevent.OnClientEvent:Connect(function(mchangecheck, daytime)
	if not mchangecheck then return end
	if daytime then uis.MouseIconEnabled = true else uis.MouseIconEnabled = false end
end)

--[[

rs.Heartbeat:Connect(function()
	if mouse.Icon == id or uis.MouseIcon == id then
		mouse.Icon = normal
		uis.MouseIcon = normal
	elseif mouse.Icon == id2 or uis.MouseIcon == id2 then
		mouse.Icon = far
		uis.MouseIcon = far
	end
end)

]]

yes, both images are image ids not decal ids

the task.defer function works fine, and the mouse icon changes to the image

now here’s my issue:

once i equip a tool which changes the mouse.icon and uis.mouseicon both to the gun icon and then unequip it, it shows the default mouse icon and doesn’t change back unless it’s manually changed

while wait()/task.wait() do loops don’t seem to work, runservice.heartbeat and renderstepped don’t work either

i’m 100% sure there are no scripts changing the mouse icon aside from the tool cursor script, this is the code for it:

local storage = game:GetService("ReplicatedStorage")
local uis = game:GetService("UserInputService")
local cursors = storage:WaitForChild("cursors")

local icon = cursors:WaitForChild("gun").Value
local iconr = cursors:WaitForChild("gunreload").Value

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local char = plr.Character or plr.CharacterAdded:Wait()

local tool = script.Parent

local cursor = nil

local function update()
	if cursor and tool.Parent == char then
		cursor.Icon = tool.Enabled and icon or iconr
	else
		mouse.Icon = "rbxassetid://13902810543"
		uis.MouseIcon = "rbxassetid://13902810543"
	end
end

local function equip(m)
	cursor = m
	update()
end

local function change(property)
	if property == "Enabled" then
		update()
	end
end

tool.Equipped:Connect(equip)
tool.Unequipped:Connect(equip)
tool.Changed:Connect(change)

yah the code is a rewritten version of the old tool cursor lol

i’m not sure if i explained my situation well enough, so please let me know if you need more information

2 Likes

script is a localscript in startergui btw

Can you explain a bit more about the issue? I’m not sure what you mean by “it shows the default mouse icon”, by default mouse icon do you mean the Roblox default? Please explain what you expected so I can try and help you.

the default mouse icon as in the default roblox mouse icon, and i expected it to show the mouse icon that i’m trying to make it show

I wasn’t able to identify the issue but here are some stuff that I noticed:

  • It’s not a good idea to have the cursor variable in the second script, you only set it when you Equipped event gets fired so the update function uses it, I recommend removing that variable and passing m to the update function.

  • You changed the mouse icon twice, once in mouse and once using UserInputService. You only need to set it once.

  • I see that in the first if statement inside of update function, you set cursor.Icon to a boolean value.

I hope some of these notes will help you, as I’m not sure what the issue might be.

the second script was a rewrite of the original script i found in the tool, i didn’t feel like completely reworking it, that’s why it works like that

i changed the mouse icon twice to make sure one of them don’t work, i have tried to use only one with both mouse.icon and uis.mouseicon, everything shows the same result

nopes, and means if tool.Enabled then it sets it to icon, or means if not it sets it to iconr if that makes sense

1 Like

also, i decided to just not change the mouse icon with tools at all throughout the entire game, it won’t cause issues so theres no point in changing it imo

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