Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 7 years ago
Edited 7 years ago

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)

01local clickDetector = game.Workspace.Part.ClickDetector
02local icon = "rbxassetid://878096274"
03local icon2 = "rbxassetid://878076293"
04clickDetector.MouseHoverEnter:connect(function(player)
05    local mouse = player:GetMouse()
06    mouse.Icon = icon
07end)
08clickDetector.MouseHoverLeave:connect(function(player)
09    local mouse = player:GetMouse()
10    mouse.Icon = icon2
11end)

This is the script that i've been using.

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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".

1function Search(ItemToSearch)
2    for i, v in pairs(ItemToSearch:GetChildren()) do
3        if v:IsA("Part") then
4            v.BrickColor = "Really red"
5        end
6        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.
7    end
8end)
9--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,

1Search(workspace)
2--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:

01local icon = "rbxassetid://878096274"
02local icon2 = "rbxassetid://878076293"
03function Search(ItemToSearch)
04    for i, v in pairs(ItemToSearch:GetChildren()) do
05        if v:IsA("ClickDetector") then
06            v.MouseHoverEnter:connect(function(Player)
07                local Mouse = Player:GetMouse()
08                Mouse.Icon = icon
09            end)
10            v.MouseHoverLeave:connect(function(Player)
11                local Mouse = Player:GetMouse()
12                Mouse.Icon = icon2
13            end)
14        end
15        Search(v)
16    end
17end
18 
19Search(workspace)
0
If you don't understand anything or need clarification, just comment. wierdgamer100 130 — 7y
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. Unity_456 47 — 7y
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. wierdgamer100 130 — 7y
0
The Filtering Enabled is disabled and there seems to be an error at line 17 (There is red line under " ) " ) Unity_456 47 — 7y
View all comments (6 more)
0
My apologies, I added an extra ")" at the end. I revised it. Sorry again for the inconvenience.. wierdgamer100 130 — 7y
0
It's fine, thanks for the help! Unity_456 47 — 7y
0
if worked accept the answer abnotaddable 920 — 7y
0
How do i accept it? (I am completely new to this website) Unity_456 47 — 7y
0
I believe there is a button under my answer that says something like "Accept answer" wierdgamer100 130 — 7y
0
I cant see any buttons except "Report" button under your answer. Unity_456 47 — 7y
Ad

Answer this question