--// Script in ServerscriptService
local Shoot = game:GetService('ReplicatedStorage'):WaitForChild'Shoot'
Shoot.OnServerEvent:connect(function(player, beginpos, endpos, accuracy, tool)
endpos = endpos * math.random(accuracy, 1)
local ray = Ray.new(beginpos, (endpos - beginpos).unit)
local hit = game.Workspace:FindPartOnRay(ray)
if (player.Character.Torso.Position - hit.Position).magnitude <= 5 then
return
end
local PartbyRay = Instance.new('Part', game.Workspace)
PartbyRay.BrickColor = player.TeamColor
PartbyRay.Locked = true
PartbyRay.Anchored = true
PartbyRay.Transparency = 0.8
PartbyRay.TopSurface = 'Smooth'
PartbyRay.BottomSurface = 'Smooth'
PartbyRay.Size = Vector3.new(0.2, 0.2, ((beginpos - endpos).magnitude))
PartbyRay.CFrame = tool.Handle.Barrel.CFrame
game:GetService('Debris'):AddItem(PartbyRay, 0.1)
end)
--// Localscript
local UIS = game:GetService('UserInputService')
local p = game.Players.LocalPlayer
local tool = script.Parent
repeat wait() until p.Character
local handle = tool:WaitForChild'Handle'
local barrel = handle:WaitForChild'Barrel'
local Mag = handle:WaitForChild'Mag'
local Aim = handle:WaitForChild'Aim'
local c = p.Character
local mouse = p:GetMouse()
UIS.InputBegan:connect(function(input, gPE)
if not gPE then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if ammo > 0 then
Firing = true
else
Firing = false
Reload()
end
end
end
end)
UIS.InputEnded:connect(function(input, gPE)
if not gPE then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
Firing = false
end
end
end)
while wait() do
if Firing == true then
if mode == 'Auto' then
wait(1 / (gunmodule.AutoBulletsPerSecond))
elseif mode == 'Semi' then
wait(1)
end
Shoot:FireServer(handle.CFrame.p, mouse.Hit.p, gunmodule.Accuracy, tool)
ammo = ammo - 1
end
end
Accuracy = math.random(0.98, 1)
Why is this shooting all over the place -.-
The Legend of Heroes Sen no Kiseki |