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)
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
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)
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.
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.
--you know what it dose...
while true do
script.Parent.Anchored= false
wait(6)
script.Parent.Anchored= true
wait(3)
end
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)
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.
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.
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)