Hi, I’ve been having a problem creating a “Laser Beam” upon shooting my raycast gun.
The problem is that I’m creating the Laser Beam, and I made it rezise using MaxRange.
Here is what’s happening:
How could I make the beam stop on the Hit position?
-- Server
local function CreateVisual(Start, End, direction)
local Center = Start + direction/2
local Distance = direction.Magnitude
local visual = Instance.new("Part", game.Workspace.Visuals)
visual.Name = "Visual"
visual.Anchored = true
visual.CanCollide = false
visual.BrickColor = BrickColor.new("Neon orange")
visual.Material = "Neon"
visual.CFrame = CFrame.new(Center, Start)
visual.Size = Vector3.new(.1, .1, direction.Magnitude)
TweenService:Create(visual, TweenInfo.new(VisualTime), {Size = Vector3.new(.05, .05, Distance), Transparency = 1}):Play()
game:GetService("Debris"):AddItem(visual, VisualTime)
end
RemoteEvent.OnServerEvent:Connect(function(plr, hit, Damage, HSMEnabled, HSM, Start, End, Direction, MaxRange)
Handle.Shoot:Play()
if hit then
if hit:GetAttribute("Health") then
local NewHealth = hit:GetAttribute("Health") - Damage
hit:SetAttribute("Health", NewHealth)
elseif hit.Parent:GetAttribute("Health") then
local NewHealth = hit.Parent:GetAttribute("Health") - Damage
hit.Parent:SetAttribute("Health", NewHealth)
end
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
if hit.Name == "Head" then
RemoteEvent:FireClient(PLR, hit, true)
if HSMEnabled then
hum:TakeDamage(Damage * HSM)
else
hum:TakeDamage(Damage)
end
elseif hit.Name == "Torso" or hit.Name == "HumanoidRootPart" then
RemoteEvent:FireClient(PLR, hit, false)
hum:TakeDamage(Damage)
elseif hit.Name == "Left Arm" or hit.Name == "Right Arm" then
RemoteEvent:FireClient(PLR, hit, false)
hum:TakeDamage(Damage / 1.2)
elseif hit.Name == "Left Leg" or hit.Name == "Right Leg" then
RemoteEvent:FireClient(PLR, hit, false)
hum:TakeDamage(Damage / 1.4)
end
TagHumanoid(hum, plr)
local HitSound = Handle.Hit:Clone()
HitSound.Parent = hit
HitSound:Play()
game.Debris:AddItem(HitSound, 1)
end
end
CreateVisual(Start, End, Direction.LookVector * MaxRange)
end)
-- Local
local MaxRange = 250
local Damage = 12
local HeadshotMultiplierEnabled = true
local HeadshotMultiplier = 1.2
local pelletCount = 1 --The number of pellets you want being shot
local maximumOffset = 0.5 --The maximum number of studs that the bullets will offset at
local filterTable = {}
local params = RaycastParams.new()
local function CastRay(Start, End)
local Dir = CFrame.new(Start, End)*CFrame.Angles(math.rad(math.random(-maximumOffset,maximumOffset)),math.rad(math.random(-maximumOffset,maximumOffset)),0)
local raycast = game.Workspace:Raycast(Start, Dir.LookVector * MaxRange, params)
if raycast then
RemoteEvent:FireServer(raycast.Instance, Damage, HeadshotMultiplierEnabled, HeadshotMultiplier, Start, End, Dir, MaxRange)
else
RemoteEvent:FireServer(nil, Damage, HeadshotMultiplierEnabled, HeadshotMultiplier, Start, End, Dir, MaxRange)
end
end