A part is instaced and Attachment1 is childed to the part and another attachment, attachment0 is childed to LeftG(Another Part) and in the end the beam gets connected to both the attachments
I want to make the beam attach to attachments but it’s not working even showing.
Note: I am using a local script to do this on the client.
Of course, because the way you made the script is:
Everytime you press Q, it takes the player’s mouse location and creates a part depending on the location. Could you tell me what exactly do you want to do with that script please or what it’s supposed to do?
local plr = game.Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
mouse.TargetFilter = workspace.DONTTOUCH -- create a model called 'DONTTOUCH' in the workspace (used so when you hit the mouse, the attachment filters properly so it doesn't get positioned out of the tower)
local towersfolder = workspace.Towers
local clicking = false
-- create beam & attachment in character (only one time)
local function createBeam()
if not char or not char.Parent then
char = plr.CharacterAdded:wait()
end
wait(2)
local At0 = Instance.new("Attachment")
At0.Name = "Attachment0"
At0.WorldPosition = char.HumanoidRootPart.Position -- to change if needed
At0.Parent = char.HumanoidRootPart -- to change if needed
At0.Position = Vector3.new(0,0,0)
local beam = Instance.new("Beam")
beam.FaceCamera = true;
beam.Color = ColorSequence.new({ColorSequenceKeypoint.new(0,Color3.new(0,0,13/51)),ColorSequenceKeypoint.new(1,Color3.new(0,0,13/51))});
beam.ZOffset = 0;
beam.Transparency = NumberSequence.new({NumberSequenceKeypoint.new(0,0,0),NumberSequenceKeypoint.new(1,0,0)});
beam.LightInfluence = 1;
beam.CurveSize0 = 1;
beam.Segments = 1;
beam.Attachment0 = At0;
beam.Texture = "rbxassetid://4768994854";
beam.CurveSize1 = 1;
beam.TextureMode = Enum.TextureMode.Static;
beam.Parent = char
beam.Enabled = false
end
createBeam()
mouse.Button1Down:connect(function() -- when mouse is clicked
if not char or not char.Parent then
char = plr.CharacterAdded:wait()
end
if clicking then
return
end
if mouse.Target then
if mouse.Target.Parent.Name == 'Towers' then -- create folder, insert all your towers in it, and change the value by the folder's name
clicking = true
local tower = mouse.Target
if tower:FindFirstChild('Attachment1') then
tower.Attachment1:Destroy() -- destroy the attachment if it exists
end
-- creates a new attachment
local At1 = Instance.new("Attachment")
At1.Name = "Attachment1"
At1.WorldPosition = tower.Position
At1.Parent = tower
At1.Position = Vector3.new(0, mouse.Origin.p.Y, 0)
-- check if the attachment is in the tower
if mouse.Hit.p.X >= tower.Position.X and mouse.Hit.p.Z >= tower.Position.Z then
At1.Position = Vector3.new(0, mouse.Hit.p.Y, mouse.Hit.p.Z)
end
if At1.Position.Y > tower.Position.Y then
At1.Position = Vector3.new(At1.Position.X, tower.Position.Y, At1.Position.Z)
end
-- activates the beam
char.Beam.Attachment1 = At1
At1.Visible = true
char.Beam.Enabled = true
end
end
end)
mouse.Button1Up:connect(function() -- when mouse is up
clicking = false
end)
I roughly made that in an hour, the script works though. However, it will probably need some adjustments for the mouse position, but here’s a quick video: