I am trying to make a custom cursor by making an imagelabel follow the actual cursor. To add onto this, I also want to allow it to show clickdetector icons from the property in the actual clickdetector. When i hover over a clickdetector with my code, it gives me this error: Players.Max_thenoob6284.PlayerGui.MouseIcon.ImageLabel.UpdateMouse:8: attempt to index string with 'Position'
Here is the code and Hierarchy for my custom cursor.
local UIS = game:GetService("UserInputService")
local GS = game:GetService("GuiService")
local RS = game:GetService('RunService')
local Mouse = game.Players.LocalPlayer:GetMouse()
local image = script.Parent
RS.RenderStepped:Connect(function()
-- line below responsible for error
image.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y + GS:GetGuiInset().Y)
if Mouse.Target and Mouse.Target:FindFirstChildOfClass("ClickDetector") then
image = Mouse.Target:FindFirstChildOfClass("ClickDetector").CursorIcon
end
end)
UIS.MouseIconEnabled = false
There’s a much easier way to set a custom cursor icon - use the Mouse.Icon property.
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
mouse.Icon = "rbxassetid://ID_HERE"
--you could also do "http://www.roblox.com/asset/?id=ID_HERE"
I’ve also noticed a bug with the mouse icon that makes the cursor move by a pixel whenever I click. This is noticeable because my game is in First Person.
I think the GetGuiInset().Y isn’t returning just a Number. Maybe try removing it first and see if it works then then we go from there I’m not in studio rn though.
that is not the issue. it still shows the error after removing that. the line is simply to account for the topbar that offsets the mouse position variables.