I want to make a block along a raycast for the visual effect of a laser weapon. I’ve done this before with a really similar script, but this time, the origin of the laser is right but goes towards the workspace origin, or somewhere around there.
I haven’t found any help related to this, and the next part that I want to do requires this to be fixed.
local Direction = Origin.CFrame.LookVector * 5000
local Hit = workspace:Raycast(Origin.Position,Direction,raycastParams)
local Laser = game.ServerStorage.Laser:Clone()
if Hit then
Laser.Mesh.Scale = Vector3.new(0.5,0.5,Hit.Distance)
Laser.CFrame = CFrame.new(Origin.Position,Direction) * CFrame.new(0,0,-Hit.Distance/2)
local Explosion = Instance.new("Explosion")
Explosion.Position = Hit.Position
Explosion.BlastRadius = 10
Explosion.Parent = workspace
local Sound = game.ServerStorage.Explosion:Clone()
Sound.Parent = Hit.Instance
Sound:Play()
game:GetService("Debris"):AddItem(Sound,Sound.TimeLength)
else
Laser.Mesh.Scale = Vector3.new(0.5,0.5,5000)
Laser.CFrame = CFrame.new(Origin.Position,Direction) * CFrame.new(0,0,-5000/2)
end
The screenshot shows the laser firing twice, both towards a completely different direction than where the turret was facing.