There is a script that create a beam in front of you when you click with the mouse. Normally, the beam is supposed to grows to where you clicked with the mouse until a certain size (It does not grows over a certains size, for example : 75). Also, only the front part must grows. When you click, the part appears a grows.... from both side (Front and Back) and i dont know how to change the position to make the begining of the beam always starts in front of you and the end finishes to where you click.
I've used Ray and CFrame to define the first position (when you just clicked) but not the position for when it's growing.
I mean :
local tool = script.Parent
local ray = Ray.new(tool.Emitter.CFrame.p, (player:GetMouse().Hit.p - tool.Emitter.CFrame.p).unit * 75)
local part,position = game.Workspace:FindPartOnRay(ray, player.Character, false, false)
game.ReplicatedStorage.Beam:FireServer(tool, position)
--this part is from a local script in a tool
--this part is in a Script in ServerScriptService
game.ReplicatedStorage.Beam.OnServerEvent:connect(function(player, tool, position)
local distance = (tool.Emitter.CFrame.p - position).magnitude
for i = 0,distance,6 do
beam.CFrame = CFrame.new(tool.Emitter.CFrame.p, position)
wait(0.001)
end
for i = 0,25 do
beam.Size = beam.Size + Vector3.new(0,0,2.96) -- this make the beam grows from both side (Front and Back). Resize() cant work because it makes some problem with .Touched event
wait(0.01)
end
end)
Now , all i need is to define the position each time the part grows, but i dont know how to do this. Could someone help me ?

1 comment
I already tried it and the beam always move to the same direction, not where i clicked