local Char = Player.Character or Player.CharacterAdded:Wait()
local Gun = (function() : Accessory?
for Index, Value in next, Char:GetChildren() do
if Value:IsA("Accessory") then
if GunData[Value.Name] then
return Value
end
end
end
return nil
end)()
if not Gun then return warn("No gun") end
local Bullet = game.ReplicatedStorage.Objects.VFX.Bullet:Clone()
local Range : number = Config.Range
local Speed : number = Config.Speed
local FlightTime : number = Speed * Range
local ShootPart : CFrame = Gun.ShootPart.CFrame + Gun.ShootPart.CFrame.LookVector * 5
local LookAt = CFrame.lookAt(ShootPart.Position, Hit.Position)
Functions.AddObject(Bullet)
local ColorSeq = Colors[GunData[Gun.Name].LazerType]
Bullet.Body.Beam_1.Color = ColorSeq
Bullet.Body.Beam_2.Color = ColorSeq
Bullet:SetPrimaryPartCFrame(LookAt)
Bullet.PrimaryPart.Position = ShootPart.Position
Bullet.Body.Pos.Position = ShootPart.Position
Bullet.Parent = game.Workspace.Bullets
local Current : Vector3, Last : Vector3 = ShootPart.Position, ShootPart.Position
coroutine.wrap(function()
local Suc, Fail = pcall(function()
for Num = 0, Range, ((Range / FlightTime) * 60) * Config.BulletSpeedMultipler do
if not Bullet:FindFirstChild("Body") then Bullet:Destroy() break end
Bullet.Body.Pos.Position = Current
local RayCast = RayCast(Last, Current, {Player.Character})
if RayCast then
DoEffects(RayCast.Position, RayCast.Instance)
Bullet:Destroy()
break
end
Last = Current
Current = ShootPart.Position + (LookAt.LookVector * Num) - VEC(0, Config.BulletDropAmount * Num ,0)
RS.Heartbeat:Wait()
end
end)
if Fail then
warn(Fail)
Bullet:Destroy()
end
end)()
end
Any ideas on how to fix this? Server and client have the same code apart from the bullet part.