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

how to apply this clickdetector to work for every part that is a dollar?

Asked by
x28_97 -9
4 years ago
Edited 4 years ago

hello so i have money, or better known as a part in workspace and i have this clickdector code that only works for one dollar, code below, but it does not work with the parts that are cloned

game.Workspace:WaitForChild("dollar").ClickDetector.MouseClick:Connect(function()
    print("WOWWWWWWW")
end)

2 answers

Log in to vote
0
Answered by 4 years ago

MAKE SURE TO PUT THE SCRIPT INSIDE THE PART.

script.Parent.ClickDetector.MouseClick:Connect(function()
    - - Event
end)

Now if you clone the part, the script should be cloned as well. The reason why your code didn't work is because you told the script to look for that object only and not any other objects like it. It should work now.

Ad
Log in to vote
0
Answered by
Despayr 505 Moderation Voter
4 years ago

If you are looking for this block of code to work for every click detector in workspace called 'Dollar', then the best thing to do would be to use a for loop and search through the descendants in workspace.

Example

for _, detectors in pairs(workspace:GetDescendants()) do 
    if detectors:IsA("ClickDetector") and tostring(detectors) == "Dollar" then
        --your code

    end
end

A for loop will run the same code for every click detector that is named "Dollar"

Now we will attach an event to all of them

for _, detectors in pairs(workspace:GetDescendants()) do 
    if detectors:IsA("ClickDetector") and tostring(detectors) == "Dollar" then

        detectors.MouseClick:Connect(function(playerWhoClicked)
            print("OwO UwU")
        end)

    end
end
0
im sorry i get how this works but im still having issues getting the click detector to reference the dollar >.< ive tried adding detectors.ClickDetector.MouseClick:Connect(function(playerWhoClicked) but that didnt work also :/ x28_97 -9 — 4y
0
Did you use my exact code? If so, then change Dollar to dollar Despayr 505 — 4y

Answer this question