Hello, I would like to know how can I fix this little problem → the beam is not correctly on the ShootPos in my weapon, I do not know if I can fix it but if you have an idea tell me :
https://gyazo.com/87783cdbd079db7bd4d810ca08a83de2
Code (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 CreateBullet(nameGun, pos, dmg, col, origplr)
local char = origplr.Character
local gun = char:FindFirstChild(nameGun)
local cp = gun:FindFirstChild("ShootPos").CFrame.p
local ray = Ray.new(cp, (pos - cp).unit * 300)
local part, position = workspace:FindPartOnRay(ray, char, false, true)
local beam = Instance.new("Part", workspace)
beam.BrickColor = col
beam.FormFactor = "Custom"
beam.Material = Enum.Material.Neon
beam.Transparency = 0.8
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local distance = (gun:FindFirstChild("ShootPos").CFrame.p - position).magnitude
beam.Size = Vector3.new(0.04, 0.04, distance)
beam.CFrame = CFrame.new(cp, position) * CFrame.new(0, 0, -distance / 2)
rs.Events.Items.Shoot:FireServer("ARI", mouse.Hit.p, DamageAmmo.Value, ColorAmmo.Value, part)
game:GetService("Debris"):AddItem(beam, 0.05)
end
local function handleAction()
pressing = true
local char = plr.Character
while pressing do
local isEquipped = char:FindFirstChild("ARI")
local canShoot = rs.Events.Items.GetARICanShoot:InvokeServer()
local isReloading = rs.Events.Items.GetARIReloading:InvokeServer()
if isEquipped and canShoot and not isReloading then
rs.Events.Items.ARIShoot:FireServer(pressing) -- Animation
CreateBullet("ARI", mouse.Hit.p, DamageAmmo.Value, ColorAmmo.Value, plr)
task.wait(0.05)
end
end
end
rs.Events.Items.Shoot.OnClientEvent:Connect(function(rename, repos, redmg, reammo, replr)
CreateBullet(rename, repos, redmg, reammo, replr)
end)
mouse.Button1Down:Connect(handleAction)
mouse.Button1Up:Connect(function()
pressing = false
end)