Hey everyone, so I posted this problem a couple weeks back, but I never really got an answer. Anyway, I want to create a beam that can move via the mouse movement, but i've been running into many problems.
Here's the current script:
(Local Script)
Mouse.Button1Down:Connect(function()
mousedown = true
CVB:FireServer() -- Creates the Visual Part and Beam
Mouse.move:Connect(function()
if not mousedown and not player and not Humanoid and not Humanoid.Health > 0 and not Torso and not debounce then return end
local MouseHit = Mouse.Hit
local HumanoidRoot = Character:WaitForChild("HumanoidRootPart")
local Distance = (Torso.Position-MouseHit.Position).magnitude
if Distance > 500 then Distance = DistanceMax end
FlameStart:FireServer(mousedown,Torso,MouseHit,Distance) -- Creates the RayCast and updates the beam's CFrame
end)
end)
After firing the remote event the server script picks it up and does all of the beam's CFrame repositioning. On the server side a function creates a Visual part and beam Part. (P.S. I did not include the full function that creates the parts, if you need me to do so just comment please)
FlameStart.OnServerEvent:connect(function(...)
local tuple = {...}
local player = tuple[1]
local mousehit = tuple[2]
local Torso = tuple[3]
local MouseHit = tuple[4]
local Distance = tuple[5]
if Torso and MouseHit and player.Character and Distance then
--Ray Cast--
local ray = Ray.new(Torso.CFrame.Position, (MouseHit.Position - Torso.CFrame.Position).Unit * 500)
local part,position = workspace:FindPartOnRay(ray,player.Character,false,true)
--UpdateBeam's CFrame --
beam.Size = Vector3.new(0.5,0.5,Distance)
beam.CFrame = CFrame.new(Torso.CFrame.Position ,position) * CFrame.new(0,0,-Distance/2)
end
end
end
This script has worked, but the only problem is that sometimes the beam glitches out and is positioned wrong.
This is a video of my current progress](https://photos.app.goo.gl/46YabKKzf2FX9FDR8)
All help would be appreciated, thanks alot
btw if you need help visualizing Im trying to make the beam like in lego marvel superheros.
Here's the link https://www.youtube.com/watch?v=eqqBj3981SU
