Hello, why is there a break between the weapon and the beam? Sometimes the beam is not visible.
Sometimes it does not create the beam and parent it to workspace.
https://gyazo.com/7d7aef54751807fcb498570cbe788823
Client:
local plr = game:GetService("Players").LocalPlayer
local mouse = plr:GetMouse()
local rs = game:GetService("ReplicatedStorage")
local pressing = false
local ColorAmmo = script.ColorAmmo
local DamageAmmo = script.DamageAmmo
local function handleAction()
pressing = true
local char = plr.Character
local possibleARI = char:FindFirstChild("ARI")
while true do
local isEquipped = rs.Events.Items.GetARIEquipped:InvokeServer()
if isEquipped then
local isReloading = rs.Events.Items.GetARIReloading:InvokeServer()
if not isReloading then
if pressing then
rs.Events.Items.ARIShoot:FireServer(pressing)
rs.Events.Items.Shoot:FireServer("ARI", mouse.Hit.p, DamageAmmo.Value, ColorAmmo.Value)
task.wait(0.1)
end
end
end
end
end
mouse.Button1Down:Connect(handleAction)
mouse.Button1Up:Connect(function()
pressing = false
end)
Server :
local rs = game:GetService("ReplicatedStorage")
local event = rs.Events.Items.Shoot
event.OnServerEvent:Connect(function(plr, nameGun, mousepos, degat, color)
local char = plr.Character
local gun = char:FindFirstChild(nameGun)
if gun then
local cp = gun:FindFirstChild("ShootPos").CFrame.p
local ray = Ray.new(cp, (mousepos - cp).unit * 300)
local part, position = workspace:FindPartOnRay(ray, char, false, true)
local beam = Instance.new("Part", workspace)
beam.BrickColor = color
beam.FormFactor = "Custom"
beam.Transparency = 0.8
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local distance = (cp - position).magnitude
beam.Size = Vector3.new(0.04, 0.04, distance)
beam.CFrame = CFrame.new(cp, position) * CFrame.new(0, 0, -distance / 2)
game:GetService("Debris"):AddItem(beam, 0.1)
if part then
local humanoid = part.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
end
if humanoid then
humanoid:TakeDamage(degat)
end
end
end
end)