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

How would I make this affect multiple objects named "Tree"?

Asked by
Synth_o 136
5 years ago
local Players = game:GetService("Players").LocalPlayer
local Tool = script.Parent
local gun = script.Parent.Handle
local mouse = Players:GetMouse()
local deb = true
Tool.Equipped:Connect(function()
    script.Parent.Beam.Enabled = false
    mouse.Button1Down:Connect(function()
        if game.Workspace.Tree.Name == "Tree" then
            script.Parent.Beam.Enabled = true
            script.Parent.Beam.Attachment0 = Tool.Handle.Main_Attatchment
            script.Parent.Beam.Attachment1 = workspace.Tree.Atta.TreeAttatchment
            workspace.Tree.Atta.TreeAttatchment.Position = Vector3.new(mouse.Target.CFrame)
            wait(1.5)
            script.parent.Beam.Enabled = false
        end
    end)
end)

Right now this only affects one object named tree how would I make it affect more?

0
I recommend using Tool.Activated event in replace of the Line 8 use of Button1Down. xPolarium 1388 — 5y
0
LOLLLLLLLLL greatneil80 2647 — 5y
0
I named it tree :] greatneil80 2647 — 5y

2 answers

Log in to vote
2
Answered by
xPolarium 1388 Moderation Voter
5 years ago
Edited 5 years ago

Use a for loop to get the children of an object (This case, it is workspace) and find the ones named tree. If it is a tree, do stuff with the tree.

for _, obj in pairs(workspace:GetChildren()) do
    if obj.Name == "Tree" then
        script.Parent.Beam.Enabled = true
        script.Parent.Beam.Attachment0 = Tool.Handle.Main_Attatchment
        script.Parent.Beam.Attachment1 = workspace.Tree.Atta.TreeAttatchment
        workspace.Tree.Atta.TreeAttatchment.Position = Vector3.new(mouse.Target.CFrame)
        wait(1.5)   
        script.parent.Beam.Enabled = false
    end
end

More on for loops

0
Either that or place all your trees in the same parent so you just need to get that objects children gullet 471 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

Just put all the trees into a model called tree

0
lol SloganRightHere 37 — 5y

Answer this question