Problem hiding roblox cursor

Hey, I made a custom cursor system that is all working, yet the issue I come across is trying to hide the Roblox system cursor. For some reason, it isn’t being hidden.

Help will be greatly appreciated.

local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local module = {}

local cursorGui
local cursorImage
local moveConnection
local clickConnection
local isEnabled = false
local lastTween

local CURSOR_ASSET = "rbxassetid://9618276643"
local CURSOR_SIZE = 64
local CURSOR_OFFSET_Y = 57
local CLICK_SCALE = 0.9
local CLICK_TWEEN_TIME = 0.08

local function ensureCursorGui()
	if cursorGui then return end

	local player = Players.LocalPlayer
	local playerGui = player:WaitForChild("PlayerGui")

	cursorGui = Instance.new("ScreenGui")
	cursorGui.Name = "CustomCursorGui"
	cursorGui.ResetOnSpawn = false
	cursorGui.IgnoreGuiInset = true
	cursorGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
	cursorGui.DisplayOrder = 9999
	cursorGui.Parent = playerGui

	cursorImage = Instance.new("ImageLabel")
	cursorImage.Name = "CursorImage"
	cursorImage.Size = UDim2.fromOffset(CURSOR_SIZE, CURSOR_SIZE)
	cursorImage.AnchorPoint = Vector2.new(0.5, 0.5)
	cursorImage.BackgroundTransparency = 1
	cursorImage.Image = CURSOR_ASSET
	cursorImage.ImageColor3 = Color3.new(1, 1, 1)
	cursorImage.ZIndex = 9999
	cursorImage.Visible = false
	cursorImage.Active = false
	cursorImage.Selectable = false
	cursorImage.Parent = cursorGui
end

local function clickAnimation()
	if not cursorImage then return end

	local shrinkTween = TweenService:Create(cursorImage, TweenInfo.new(CLICK_TWEEN_TIME, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {
		Size = UDim2.fromOffset(CURSOR_SIZE * CLICK_SCALE, CURSOR_SIZE * CLICK_SCALE),
	})
	local restoreTween = TweenService:Create(cursorImage, TweenInfo.new(CLICK_TWEEN_TIME, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {
		Size = UDim2.fromOffset(CURSOR_SIZE, CURSOR_SIZE),
	})

	shrinkTween:Play()
	shrinkTween.Completed:Connect(function()
		restoreTween:Play()
	end)
end

function module.Enable()
	if isEnabled then return end
	isEnabled = true

	ensureCursorGui()
	cursorImage.Visible = true
	
	UserInputService.MouseIconEnabled = false

	-- Follow mouse
	moveConnection = UserInputService.InputChanged:Connect(function(input)
		if input.UserInputType == Enum.UserInputType.MouseMovement then
			local targetPos = UDim2.fromOffset(input.Position.X, input.Position.Y + CURSOR_OFFSET_Y)
			if lastTween then lastTween:Cancel() end
			lastTween = TweenService:Create(cursorImage, TweenInfo.new(0.05), { Position = targetPos })
			lastTween:Play()
		end
	end)

	-- Play click animation on left click
	clickConnection = UserInputService.InputBegan:Connect(function(input, gameProcessed)
		if gameProcessed then return end -- respect UI interactions
		if input.UserInputType == Enum.UserInputType.MouseButton1 then
			clickAnimation()
		end
	end)
end

function module.Disable()
	if not isEnabled then return end
	isEnabled = false

	UserInputService.MouseIconEnabled = true

	if moveConnection then
		moveConnection:Disconnect()
		moveConnection = nil
	end
	if clickConnection then
		clickConnection:Disconnect()
		clickConnection = nil
	end
	if lastTween then
		lastTween:Cancel()
		lastTween = nil
	end

	if cursorImage then
		cursorImage.Visible = false
	end
end

function module.SetColor(color: Color3)
	if cursorImage then
		TweenService:Create(cursorImage, TweenInfo.new(0.15), { ImageColor3 = color }):Play()
	end
end

function module.Destroy()
	module.Disable()
	if cursorGui then
		cursorGui:Destroy()
		cursorGui = nil
	end
end

return module```

I have tested the script myself and it works fine, are you sure you aren’t just confusing it with the custom cursor? Try setting the cursor asset id to something else.

I mean the custom cursor works fine, the main issue was just Roblox system cursor isn’t going away. I do have a gun system so maybe something else is overriding the cursor.

Issue was found, gun system was the cause of the issue, the custom system is completely working.

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