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

Why the part with script not work when i use Clone Tool?

Asked by
OnaKat 444 Moderation Voter
5 years ago

I make anchor part that when click it will anchor/not anchor.

It work as well but when i use clone tool the clone part not work.

Here script

local part = script.Parent

script.Parent.ClickDetector.MouseClick:Connect(function()
    if part.BrickColor == BrickColor.new("Lime green") then
        wait(0.1)
        part.BrickColor = BrickColor.new("Really red")
    elseif part.BrickColor == BrickColor.new("Really red") then
        wait(0.1)
        part.BrickColor = BrickColor.new("Lime green")
    end
end)

if part.BrickColor == BrickColor.new("Lime green") then
    part.Anchored = true
elseif part.BrickColor == BrickColor.new("Really red") then
    part.Anchored = false
end

1 answer

Log in to vote
0
Answered by
crywink 419 Moderation Voter
5 years ago

If you're using the regular HopperBin build tools, the clone tool will not clone the descendants of the part. Therefore your code will not clone to the next part.

If you wanted this to work for cloned parts, you would probably want to do the following...

We're going to start out by popping a script in ServerScriptService and make sure your special parts are named something distinctive so we know to connect our event.

local partName = "clickyPart" -- change this to the name of the part

game.Workspace.ChildAdded:Connect (function(child) -- fires when something new is added to the workspace
    if child:IsA("BasePart") and child.Name == partName then
        local clickDetector = Instance.new("ClickDetector") -- make a new clickdetector
        clickDetector.Parent = child

        clickDetector.MouseClick:Connect(function()
            if child.BrickColor == BrickColor.new("Lime green") then
                wait(0.1)
                child.BrickColor = BrickColor.new("Really red")
            elseif child.BrickColor == BrickColor.new("Really red") then
                wait(0.1)
                child.BrickColor = BrickColor.new("Lime green")
            end
        end)

        if child.BrickColor == BrickColor.new("Lime green") then
            child.Anchored = true
        elseif child.BrickColor == BrickColor.new("Really red") then
            child.Anchored = false
        end
    end
end)    

If this didn't help or if you're having any other issues, just comment on the answer and I'll try to help you further.

If this helped, remember to accept and upvote this answer.

Ad

Answer this question