It's been smooth sailing making this gun. Only a couple errors and minor mistakes along the way. But I have a feeling this is where I start to pull my hair out since I'm no good at maths or Coordinate Frame/Vector calculations. I need this shotgun to shoot in a spread. As in, multiple shots which each slightly deviate from the mouse's position. (I haven't handled damage yet I'll do that myself in a bit since I don't need help with that.) I will post my scripts under this thread 🙂
#How to make shotgun shoot with spread?
6 messages · Page 1 of 1 (latest)
It's not letting me post my scripts?
Umm.
Server Script:
local Tool = script.Parent
local gun1grip = nil
local gun2grip = nil
local equipped = false
Tool.Equipped:Connect(function()
equipped = true
local Char = Tool.Parent
local Hum : Humanoid = Char.Humanoid
if Char["Right Arm"]:FindFirstChild("RightGrip") then
Char["Right Arm"].RightGrip:Destroy()
end
gun1grip = Instance.new("Motor6D", Char["Right Arm"])
gun1grip.Name = "Gun1Grip"
gun1grip.Part0 = Char["Right Arm"]
gun1grip.Part1 = Tool.Model.Gun1
gun1grip.C0 = Char["Right Arm"]["RightGripAttachment"].CFrame
gun1grip.C1 = Tool.Grip
gun2grip = Instance.new("Motor6D", Char["Left Arm"])
gun2grip.Name = "Gun2Grip"
gun2grip.Part0 = Char["Left Arm"]
gun2grip.Part1 = Tool.Model.Gun2
gun2grip.C0 = Char["Left Arm"]["LeftGripAttachment"].CFrame
gun2grip.C1 = Tool.Grip
end)
Tool.Unequipped:Connect(function()
equipped = false
gun1grip:Destroy()
gun2grip:Destroy()
end)
script.Parent.Shoot.OnServerEvent:Connect(function(player, shottype, mouse)
coroutine.resume(coroutine.create(function()
local origin = nil
if shottype == "left" then
Tool.Model.Gun2.Fire:Play()
origin = Tool.Model.Gun2.Attachment.WorldPosition
elseif shottype == "right" then
Tool.Model.Gun1.Fire:Play()
origin = Tool.Model.Gun1.Attachment.WorldPosition
end
local distance = (origin - mouse.Position).Magnitude
local p = Instance.new("Part", game.Workspace)
p.Anchored = true
p.CanCollide = false
p.Material = Enum.Material.Neon
p.Color = Color3.new(1,1,0)
p.Size = Vector3.new(0.1, 0.1, distance)
p.CFrame = CFrame.new(origin, mouse.Position)*CFrame.new(0, 0, -distance/2)
wait(0.05)
p:Destroy()
end))
end)
I can put my server script but not my client one...