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?
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