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 6 years ago
Edited 6 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)

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

Log in to vote
0
Answered by 6 years ago
Edited 6 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".

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)
0
If you don't understand anything or need clarification, just comment. wierdgamer100 130 — 6y
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 — 6y
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 — 6y
0
The Filtering Enabled is disabled and there seems to be an error at line 17 (There is red line under " ) " ) Unity_456 47 — 6y
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 — 6y
0
It's fine, thanks for the help! Unity_456 47 — 6y
0
if worked accept the answer abnotaddable 920 — 6y
0
How do i accept it? (I am completely new to this website) Unity_456 47 — 6y
0
I believe there is a button under my answer that says something like "Accept answer" wierdgamer100 130 — 6y
0
I cant see any buttons except "Report" button under your answer. Unity_456 47 — 6y
Ad

Answer this question