Help me... The cursor icon aint changing (PLEASE HELP)

local icon = script.Parent
local obj = script.Parent.Parent

local iconfalse = "rbxassetid://10575280294"
local icontrue = "rbxassetid://129875024"

while true do
	wait(0.1)
	if obj.Anchored == true then
		icon.CursorIcon = icontrue
		print(icontrue)
		wait(0.1)
	else
		icon.CursorIcon = iconfalse
		print(iconfalse)
		wait(0.1)
	end

end

This script SOULD be checking whether the “obj” variable’s “Anchored” property is set to true or false.

If the “Anchored” property is true, then the “icon” variable’s “CursorIcon” is set to the “icontrue” asset ID, which is an image asset. (i use a ClickDetector)
image

If the “Anchored” property is false, then the “icon” variable’s “CursorIcon” is set to the “iconfalse” asset ID, which is another image asset.

The script continuously checks the “Anchored” property in a loop and updates the “CursorIcon” accordingly.

BUT…

it aint working… and i dont know why, there are no errors…i checked if it would print in the console

...
print(icontrue)
...
...
print(iconfalse)
...

and it did print in the console…
image

but it dident change the cursor icon…

PLEASE SOME HELP

I believe you made your cursor image way too small. You should also be using events.

Code:

local icon = script.Parent
local obj = icon.Parent

local iconfalse = "rbxassetid://10575280294"
local icontrue = "rbxassetid://129875024"

obj:GetPropertyChangedSignal("Anchored"):Connect(function()
	icon.CursorIcon = obj.Anchored and icontrue or iconfalse
end)
2 Likes

dosent work for me… the mouse icon stays true

icontrue 
1 Like

robloxapp-20240127-2000001.wmv (591.3 KB)

1 Like

This is an interesting case, the CursorIcon property isn’t replicating from the server to the client. That is the property changes on the server, but not the client. I found an alternative way to accomplish what you need, but I would still like to find out why this doesn’t work like it should.

This requires a value in the part called AnchorCheck (I used a string value but it doesn’t really matter). Then a local script in StarterPlayerScripts called AnchorChecker with this code.

local RunService = game:GetService("RunService")

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

local anchoredIcon = "rbxassetid://0" --Change to anchoredIcon
local unanchoredIcon = "rbxassetid://0" --Change to unAnchoredIcon

local anchored

RunService.RenderStepped:Connect(function()
	if not mouse.Target or not mouse.Target:FindFirstChild("AnchorCheck") then mouse.Icon = ""; return end --Not pointed at object
	
	local object = mouse.Target

	if anchored == object.Anchored and mouse.Icon ~= "" then return end --Property hasn't changed
	
	if object.Anchored then
		mouse.Icon = anchoredIcon
	else
		mouse.Icon = unanchoredIcon
	end
	
	anchored = object.Anchored --Store value for checking
end)

I hope this will work, of course preferably you would use an event that detects when the property changes. This is probably the simplest way to do it and has checks so that it is not constantly changing the mouse icon to what it was. This overides the click detectors default mouse image to and you can still use the click detector to detect the click of course. Hopefully you can figure out how to get the cursor icon to change in the click detector and use Katrist’s method, but it wouldn’t replicate from the server to the client correctly for me.

Also your image is way to big, I would make it a square of 20-30 pixels. I’m not an expert on this or how it would scale on different devices but it would help.

still dosent work for me… idk what im doing wrong…
(i feel so dumb)

Check the name of the part, and make sure that the local script is in StarterPlayerScripts, if it doesn’t work then, post a video and maybe screenshots.

Inside the part i have this script

--you know what it dose...
while true do
	script.Parent.Anchored= false
	wait(6)
	script.Parent.Anchored= true
	wait(3)
end

image


And in StarterPlayerScripts i have the script

local RunService = game:GetService("RunService")

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

local anchoredIcon = "rbxassetid://5923741518" --Change to anchoredIcon
local unanchoredIcon = "rbxassetid://15694319394" --Change to unAnchoredIcon

local anchored = game.Workspace:WaitForChild("Part")

RunService.RenderStepped:Connect(function()
	if not mouse.Target or not mouse.Target:FindFirstChild("AnchorCheck") then mouse.Icon = ""; return end --Not pointed at object

	local object = mouse.Target

	if anchored == object.Anchored and mouse.Icon ~= "" then return end --Property hasn't changed

	if anchored.Anchored then
		mouse.Icon = anchoredIcon
	else
		mouse.Icon = unanchoredIcon
	end

	anchored = object.Anchored --Store value for checking
end)


And it dosent change my mouse icon
robloxapp-20240127-2234082.wmv (575.7 KB)

1 Like
...
	if anchored.Anchored then
		mouse.Icon = anchoredIcon
		print(anchoredIcon)
	else
		mouse.Icon = unanchoredIcon
		print(unanchoredIcon)
	end
...

i tryed it with prints but… they dont come out the console

1 Like

You can have the click detector in the part, but in that screenshot I don’t see a value called AnchorCheck which is essential for this to work.

1 Like

Inside the part or local script?

i tryed it in the part and it dident work…
image

1 Like

Sorry I see that you messed with the code now, anchored is not meant to be initialized to anything and you shouldn’t check in you’re code for anchored.Anchored.

Now that I think about it you also need something that checks if the player is close enough to it. I will write you a script for it, you shouldnt need to change anything and the ID’s should be the same.

local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()

local anchoredIcon = "rbxassetid://5923741518" --Change to anchoredIcon
local unanchoredIcon = "rbxassetid://15694319394" --Change to unAnchoredIcon

local maxDistance = 20 --Studs that it can reach (****MAKE SURE CLICK DETECTOR MAX DISTANCE IS SAME IF YOU USE IT)

local anchored

RunService.RenderStepped:Connect(function()
	if not mouse.Target or not mouse.Target:FindFirstChild("AnchorCheck") then mouse.Icon = ""; return end --Not pointed at object
	
	local object = mouse.Target
	
	if (player.Character.HumanoidRootPart.Position - mouse.Hit.Position).Magnitude > 20 then mouse.Icon = ""; return end


	if anchored == object.Anchored and mouse.Icon ~= "" then return end --Property hasn't changed
	
	if object.Anchored then
		mouse.Icon = anchoredIcon
	else
		mouse.Icon = unanchoredIcon
	end
	
	anchored = object.Anchored --Store value for checking
end)

Of course anchor check should be in any part you want this to work on.

2 Likes

In my testing, it worked perfectly. Make sure to set the RunContext of the script to Client, I forgot to tell you.

1 Like

I feel like you’re highly complicating this, I’m not sure if this is very performant either.

2 Likes

(sorry that i answer so late…) Thank u, you really helped me alot…
here is what i used it for…
robloxapp-20240131-1907378.wmv (3.7 MB)

-Best regards, MRX_perte

2 Likes

Of course it overcomplicated it. Like I said you would preferably want to use an event, however I tried it and it didn’t work. Of course client scripts don’t work in the workspace but the RunContext set to client seems to work, gives me another thing to research.

1 Like

That’s really cool! I’m glad I could help, you might try what @Katrist suggested with the events and the client RunContext he forgot to mention and it should be optimized, and of course less complicated. Again here’s the code:


local icon = script.Parent
local obj = icon.Parent

local iconfalse = "rbxassetid://10575280294"
local icontrue = "rbxassetid://129875024"

obj:GetPropertyChangedSignal("Anchored"):Connect(function()
	icon.CursorIcon = obj.Anchored and icontrue or iconfalse
end)

2 Likes

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