local event = game.ReplicatedStorage:WaitForChild("Events").Gun
local reloading = false
event.Shoot.OnServerEvent:connect(function(plr,mouse,Ammo,Gun)
local function reload()
for i = 1, 40 do
reloading = true
Ammo.Value = Ammo.Value + 1
wait(1)
plr.PlayerGui.Ammo.AmmoT.Text = "Ammo: "..Ammo.Value
if i == 40 then
reloading = false
end
end
end
local function shoot()
local ray = Ray.new(Gun.Handle.CFrame.p, (mouse.Hit.p - Gun.Handle.CFrame.p).unit * 20)
local beam2,position = game.Workspace:FindPartOnRay(ray,plr.Character,false,true)
local beam = Instance.new("Part")
beam.Name = "Beam"
beam.Parent = game.Workspace
beam.Shape = "Block"
beam.Material = "Neon"
beam.TopSurface = "Smooth"
beam.BottomSurface = "Smooth"
beam.Anchored = true
beam.CanCollide = false
beam.Transparency = 0.25
beam.BrickColor = BrickColor.new("New Yeller")
local distance = (Gun.Handle.CFrame.p - position).magnitude
beam.Size = Vector3.new(0.3, 0.3, distance)
beam.CFrame = CFrame.new(Gun.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
Ammo.Value = Ammo.Value - 1
if beam2 then
local h = beam2.Parent:FindFirstChild("Humanoid")
if not h then
h = beam2.Parent.Parent:FindFirstChild("Humanoid")
end
local name1 = beam2.Parent.Name
local name2 = beam2.Parent.Parent.Name
print(h)
if h then
if not game.Players:FindFirstChild(name1) or game.Players:FindFirstChild(name2) then
h:TakeDamage(1)
beam2.Transparency = beam2.Transparency + 0.2
print("Took Health")
end
end
end
mouse.Button1Up:connect(function()
beam:Destroy()
end)
end
if Ammo.Value <= 0 then
reload()
end
if Ammo.Value > 0 then
if reloading == false then shoot() else print("Reloading...")end
end
end)
This is a script in ServerScriptService ^
local plr = game.Players.LocalPlayer
local handle = script.Parent:FindFirstChild("Handle")
local Gun = script.Parent
local Ammo = Gun:FindFirstChild("Ammo")
local mouse = plr:GetMouse()
script.Parent.Equipped:connect(function()
local event = game.ReplicatedStorage:WaitForChild("Events").Gun
event.AmmoOpen:FireServer(Gun,Ammo)
print("Sent!")
if script.Parent.Equipped == true then
mouse.Button1Down:connect(function()
local event = game.ReplicatedStorage.Events.Gun
event.Shoot:FireServer(mouse,Ammo,Gun)
end)
end
end)
script.Parent.Unequipped:connect(function()
local event = game.ReplicatedStorage:WaitForChild("Events").Gun
event.AmmoClose:FireServer(Ammo)
print("Sent!")
end)
This is the script in the gun ^ LocalScript Help?
