Hi! :D I have a tool that will send a beam from its tip called BeamPart to the mouse.Hit . I don't want to create an additional part to attach the beam to it, I want to use the Attachment.Position property. Both attachments and the beam are parented to BeamPart, one attachment should permanently stay on the BeamPart, and the other one's Position property should change to match the mouse.Hit . But I am not that good with math, especially vector math, so none of my solutions worked. Here's my code:
local pl = game.Players.LocalPlayer local mouse = pl:GetMouse() local tool = script.Parent enabled = true if enabled then local function move() tool.BeamPart.tarAtt.CFrame = CFrame.new(Vector3.new(mouse.Hit.X, mouse.Hit.Y, mouse.Hit.Z)):ToObjectSpace(tool.BeamPart.CFrame) end mouse.Move:connect(move) end
so lets start off with why are u doing this in a localscript ?????? u should use remoteevents for this
local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local tool = script.Parent local enabled = true local remote = game.ReplicatedStorage.RemoteEvent if enabled then Remote:FireServer(script.Parent,mouse.hit) -- firing the remote telling it has to go to the server now end
now in server script i suggest making a part with the attachments
local remote = game.ReplicatedStorage.RemoteEvent remote.OnServerEvent:Connect(function(plr,Tool,Mouse)--[[everything under here and above end) will execute when remote fired / tool is the script.Parent u see in fireserver brackets same for mouse.Hit]] local a = Instance.new("Attachment") -- making a attachment and placing it into beampart a.Parent = tool.BeamPart local b = Instance.new("Part")--making a part to spawn it at mouse . hit b.CFrame = Mouse b.Transparency = 1 -- setting transparency to 1 so u cant see the part b.CanCollide = false -- making it so u can walk trough it b.Parent = game.Workspace local c = Instance.new("Attachment")-- storing this attachment in b c.Parent = b local beam = Instance.new("Beam") -- making a beam and conecting the 2 attachments beam.Attachment0 = a -- using the attachment in beampart beam.Attachment1 = c -- using the attachment in the mouse.hit part beam.Parent = b -- doesnt really matter where u parent it end)
if u got any questions or if this doesnt work wich i dont know it will since i diddnt try it then respond with the problem and i fix it.