Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can i make a script that changes ClickDetector cursor icon for all ClickDetectors?

I want to know how to make a script that can change ClickDetector cursor icon the way that it will be working on every ClickDetector that is located in workspace. I already tried searching and i could make it work only on one brick. (Excuse my bad english please)

local clickDetector = game.Workspace.Part.ClickDetector
local icon = "rbxassetid://878096274"
local icon2 = "rbxassetid://878076293"
clickDetector.MouseHoverEnter:connect(function(player)
    local mouse = player:GetMouse()
    mouse.Icon = icon
end)
clickDetector.MouseHoverLeave:connect(function(player)
    local mouse = player:GetMouse()
    mouse.Icon = icon2
end)

This is the script that i've been using.

1 answer

✓ Accepted answer

Hello Alexeeii,

The function that will be shown below searches everywhere in an entity, including its children, and it's children's children, and so on, for example, workspace. I like to think of it as a "deep search".

function Search(ItemToSearch)
	for i, v in pairs(ItemToSearch:GetChildren()) do
		if v:IsA("Part") then
			v.BrickColor = "Really red"
		end
		Search(v) --This repeats the search on the children of the children so it allows one to infinitely search through children of children, and their children, and their children, and so on.
	end
end)
--This would make every part that exists somewhere inside ItemToSearch turn red.

Then you'd use the function of whatever you'd like to "deep search". For example,

Search(workspace)
--This would make all parts in the workspace red, no matter where they are in the workspace.

In your case, you'd like to do things with all ClickDetectors in the workspace. So, your code would look something like this:

local icon = "rbxassetid://878096274"
local icon2 = "rbxassetid://878076293"
function Search(ItemToSearch)
	for i, v in pairs(ItemToSearch:GetChildren()) do
		if v:IsA("ClickDetector") then
			v.MouseHoverEnter:connect(function(Player)
				local Mouse = Player:GetMouse()
				Mouse.Icon = icon
			end)
			v.MouseHoverLeave:connect(function(Player)
				local Mouse = Player:GetMouse()
				Mouse.Icon = icon2
			end)
		end
		Search(v) 
	end
end

Search(workspace)

10 comments

0

If you don't understand anything or need clarification, just comment.

0

Thank you, but i forgot to mention that the script is local and located in PlayerGui and the code that you wrote might not work because of that.

0

As long as the game is filtering disabled, the code should work. If you have filtering enabled, tell me and I can revise it to work for you.

0

The Filtering Enabled is disabled and there seems to be an error at line 17 (There is red line under " ) " )

0

My apologies, I added an extra ")" at the end. I revised it. Sorry again for the inconvenience..

0

It's fine, thanks for the help!

0

if worked accept the answer

0

How do i accept it? (I am completely new to this website)

0

I believe there is a button under my answer that says something like "Accept answer"

0

I cant see any buttons except "Report" button under your answer.

This discussion is preserved as it was. New answers, comments, and votes are closed.