nah it’s fine it took a while, so here is the full (server) script + local script
local Replicated = game:FindFirstChild("ReplicatedStorage")
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
local FrameWork = Replicated.WeaponFramework
--local SE = FrameWork.Events.Shoot
local RNG = Random.new()
local TAU = math.pi * 2
local Tool = script.Parent
local Handle = Tool.Handle
local Settings = require(Tool.SettingsModule)
local Mesh = Tool.Mesh
local BarrelAttachment = Mesh:WaitForChild("BarrelAttachment")
local Aiming = false
local Tracer = Replicated.Tracer
local spread = Settings["Spread"]
local Range = Settings["Range"]
local BulletsPerShot = Settings["BulletsPerShot"]
local BurstAmount = Settings["BurstAmount"]
local RecoveryTime = Settings["RecoveryTime"]
local Sounds = Handle.Sounds
local ShootSound = Sounds.Shoot
local Equip = Sounds.Equip
local Flash = BarrelAttachment.Flash
local Smoke = BarrelAttachment.Smoke
local SE = Tool:FindFirstChild("Shoot")
Tool.Equipped:Connect(function()
Equip:Play()
end)
local rng_v = Random.new()
function RandomVectorOffset(v, maxAngle) --returns uniformly-distributed random unit vector no more than maxAngle radians away from v
return (CFrame.new(Vector3.new(), v)*CFrame.Angles(0, 0, rng_v:NextNumber(0, 2*math.pi))*CFrame.Angles(math.acos(rng_v:NextNumber(math.cos(maxAngle), 1)), 0, 0)).LookVector
end
local function GenerateSpread(InitialDirection: Vector3): {Vector3}
local SpreadDirections = {}
for i = 0, BulletsPerShot - 1 do
table.insert(SpreadDirections, RandomVectorOffset(InitialDirection, math.rad(spread)))
end
return SpreadDirections
end
SE.OnServerEvent:Connect(function(Player, Character, Hit)
Hit = Hit:FindFirstChild("Torso")
print("recieved")
local tracerClones = {} -- Create a table to store tracer clones
local OriginalSpeed = Character:FindFirstChild("Humanoid").WalkSpeed
local Gryo = nil
local Troll = Character.PrimaryPart:FindFirstChild("Troll")
Character:FindFirstChild("Humanoid").AutoRotate = false
if not Troll then
Gryo = Tool.Duplicates.BodyGyro:Clone()
Gryo.Name = "Troll"
Gryo.Parent = Character.PrimaryPart
Gryo.MaxTorque = Vector3.new(0, 0, 0)
Gryo.P = 5000
Gryo.D = 250
end
Aiming = true
task.spawn(function()
if Aiming then
repeat
task.wait()
Gryo.CFrame = CFrame.lookAt(Character.PrimaryPart.Position, Hit.Position)
--print("ROTATE")
until not Aiming
end
end)
Character:FindFirstChild("Humanoid").WalkSpeed = Settings["Slowdown"]
Gryo.MaxTorque = Vector3.new(0, 2000, 0)
task.wait(Settings["AimTime"])
for j = 0, BurstAmount - 1 do
task.wait(Settings["BurstDelay"])
ShootSound:Play()
local rp = RaycastParams.new()
rp.IgnoreWater = true
rp.FilterType = Enum.RaycastFilterType.Blacklist
rp.FilterDescendantsInstances = {Tool, Character}
local BarrelAtt = BarrelAttachment.WorldPosition
local InitialDirection = (Hit.Position - BarrelAtt).Unit
local SpreadDirections = GenerateSpread(InitialDirection, BulletsPerShot, spread)
local tracers = {} -- Table to store tracers for destruction later
for _, UnitVector in pairs(SpreadDirections) do
Flash:Emit(100)
local TracerClone = Tracer:Clone()
TracerClone.Parent = workspace
TracerClone.START.WorldPosition = BarrelAtt
TracerClone.END.WorldPosition = BarrelAtt + (UnitVector * Range)
table.insert(tracers, TracerClone) -- Store tracers for later destruction
local dir = TracerClone.END.WorldPosition - BarrelAtt
local destination = BarrelAtt + dir
local ray = workspace:Raycast(BarrelAtt, destination, rp)
-- local ray = workspace:Raycast(BarrelAtt, BarrelAtt + (UnitVector * Range), rp)
if ray then
local HitLocation = ray.Position
TracerClone.END.WorldPosition = HitLocation
--hitPart = Instance.new("Part")
--hitPart.Size = Vector3.new(0.1,0.1,0.1)
--hitPart.Position = ray.Position
--hitPart.Anchored = true
--hitPart.CanCollide = false
--hitPart.Transparency = 0.5
--hitPart.BrickColor = BrickColor.new("Bright red")
--hitPart.Parent = workspace -- Change parent if needed
Tracer.END.WorldPosition = HitLocation
local RayHit = ray.Instance
local Hum = RayHit.Parent:FindFirstChild("Humanoid")
if Hum then
Hum:TakeDamage(Settings["Damage"])
print("Hit!")
else
print("Miss!")
end
end
end
task.wait(0.1)
--hitPart:Destroy()
if BurstAmount > 1 then
for _, tracer in pairs(tracers) do
tracer:Destroy() -- Destroy tracers after a delay
end
end
end
-- Destroy all tracer clones after all iterations
for _, tracer in ipairs(tracerClones) do
task.wait(0.1)
tracer:Destroy()
end
if Gryo then
Gryo:Destroy()
end
Character:FindFirstChild("Humanoid").AutoRotate = true
Character:FindFirstChild("Humanoid").WalkSpeed = OriginalSpeed
Aiming = false
Smoke.Enabled = true
Tool.Enabled = false
task.wait(RecoveryTime)
Smoke.Enabled = false
Tool.Enabled = true
end)
local script:
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local Tool = script.Parent
local Handle = Tool.Handle
local Mesh = Tool.Mesh
local BarrelAttachment = Mesh:WaitForChild("BarrelAttachment")
local MuzzleFlash = BarrelAttachment.Flash
local Smoke = MuzzleFlash.Parent.Smoke
local Settings = require(Tool:WaitForChild("SettingsModule"))
local player = Players.LocalPlayer
local Shoot = Handle.Sounds.Shoot
local FrameWork = ReplicatedStorage.WeaponFramework
local camera = workspace.CurrentCamera
local SE = Tool:FindFirstChild("Shoot")
local function castRay()
local mouse = Players.LocalPlayer:GetMouse()
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {Tool.Parent, Tool}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude -- Choose Exclude or Include
local barrelAttachment = Tool:WaitForChild("Mesh"):WaitForChild("BarrelAttachment") -- Assuming this structure
local rayDirection = (mouse.Hit.Position - barrelAttachment.Position).Unit
local raycastResult = workspace:Raycast(barrelAttachment.Position, rayDirection * Settings["Range"], raycastParams) -- Max distance of 300
if raycastResult then
local Target = raycastResult.Instance.Parent
if Target:FindFirstChild("Humanoid") then
print(Target)
-- Create a part at the hit position for debugging
local hitPart = Instance.new("Part")
hitPart.Size = Vector3.new(0.1,0.1,0.1)
hitPart.Position = raycastResult.Position
hitPart.Anchored = true
hitPart.CanCollide = false
hitPart.Transparency = 0.5
hitPart.BrickColor = BrickColor.new("Bright red")
hitPart.Parent = workspace -- Change parent if needed
wait(1)
hitPart:Destroy()
local Character = player.Character
SE:FireServer(Character, Target)
end
else
print("Miss!")
end
end
UserInputService.InputBegan:Connect(function(input)
if Tool.Enabled then
if input.UserInputType == Enum.UserInputType.MouseButton1 and Tool:IsA("Tool") and Tool.Parent == Players.LocalPlayer.Character then
castRay()
end
else
return
end
end)