I wanted to make a shotgun so I started off by making a function fire one ray and deal damage one time. To make the shotgun I just put this function in a for loop and made the angle of all the rays random so you can see the multiple rays it shoots. The problem is no matter how many rays hit it only does damage one time.
for i = 0, 5 do --// Deleted the spread math code\\-- --// Distance calculations local distance = math.floor((rootPart.CFrame.p - mouse.Hit.p).magnitude) --// Define origin local origin = hole.CFrame local ray = Ray.new(origin.p, (look.p - origin.p).unit * range.Value) local touch, position = workspace:FindPartOnRay(ray, player.Character, false, true) --// Hit detection if touch then hitRemote:FireServer(touch) -- Something to do with this? boomRemote:FireServer(position) end shootRemote:FireServer() --// Trace if allowTracking.Value then --// Draw laser on sever laserRemote:FireServer(position) end end
Damage Script:
local function hit(plr, part) --// Start and Checks if not canShoot() then return end if not part then return end --// Get humanoid root part local character = player.Character or player.CharacterAdded:Wait() local rootPart = character:WaitForChild("HumanoidRootPart") --// Get mouse --local mouse = plr:GetMouse() if rootPart then --// Check Distance local distance = (rootPart.CFrame.p - part.CFrame.p).magnitude if distance <= range.Value then --// Checks Range --// Get Humanoid local humanoid --// Check if was was hat if part.Name == "Handle" then humanoid = part.Parent.Parent:FindFirstChild("Humanoid") else humanoid = part.Parent:FindFirstChild("Humanoid") end --// Damage calculations if humanoid and humanoid.Health > 0 then --// Check if dead local rndDamage = math.random(minDamage.Value, maxDamage.Value) local newDamage = rndDamage --//Check hit if part.Name == "Head" then newDamage = newDamage * headMultiplier.Value end humanoid:TakeDamage(newDamage ) end end end