So I am trying to make my own gun but when I shoot for the first time it takes away the ammo but doesn’t do anything else. Does anyone know a way to fix it? Here is a video: https://gyazo.com/18da623b59847c74ab14167cf94c7534
Here are my scripts too if there is anything wrong with them
-- Local Script
local firerate = 0.2
local debounce = false
local player = game.Players.LocalPlayer
local gun = script.Parent
local mouse = player:GetMouse()
function reload()
debounce = true
gun.Handle.Reload:Play()
repeat wait() until gun.Handle.Reload.Playing == false
gun.Config.Ammo.Value = gun.Config.MaxAmmo.Value
player.PlayerGui.AmmoGui.Bullets.Text = gun.Config.Ammo.Value
debounce = false
end
script.Parent.Equipped:Connect(function()
player.PlayerGui.AmmoGui.Enabled = true
player.PlayerGui.AmmoGui.Bullets.Text = gun.Config.Ammo.Value
player.PlayerGui.AmmoGui.MaxAmmo.Text = gun.Config.MaxAmmo.Value
end)
script.Parent.Unequipped:Connect(function()
player.PlayerGui.AmmoGui.Enabled = false
end)
script.Parent.Activated:Connect(function()
if debounce == false then
debounce = true
local pos = script.Parent.Parent.Humanoid.TargetPoint
local LookAt = (pos - script.Parent.Parent.Head.Position).Unit
script.Parent.Shoot:FireServer(script.Parent.Barrel.CFrame.Position, mouse.Hit.Position)
gun.Config.Ammo.Value = gun.Config.Ammo.Value - 1
player.PlayerGui.AmmoGui.Bullets.Text = gun.Config.Ammo.Value
if gun.Config.Ammo.Value == 0 then
reload()
else
wait(firerate)
debounce = false
end
end
end)
-- Server Script
local damage = math.random(10,15)
local debounce = false
script.Parent.Shoot.OnServerEvent:Connect(function(player,LookAt)
script.Parent.Shoot.OnServerEvent:Connect(function(Player, FromP, ToP)
local RayCast = Ray.new(FromP,(ToP-FromP).unit*100)
local Part,Position,Normal = game.Workspace:FindPartOnRay(RayCast,Player.Character, false,true)
local Dist = (ToP-FromP).magnitude
if not Dist then Dist = 300 end
local Lazer = Instance.new("Part")
Lazer.Parent = game.Workspace
Lazer.Anchored = true
Lazer.CanCollide = false
Lazer.BrickColor = BrickColor.new("New Yeller")
Lazer.Material = Enum.Material.Neon
Lazer.Size = Vector3.new(0.1,0.1,Dist)
Lazer.CFrame = CFrame.new(FromP,Position)*CFrame.new(0,0,-Dist/2)
game.Debris:AddItem(Lazer,0.2)
script.Parent.Muzzle.Muzzle1.Enabled = true
wait(0.2)
script.Parent.Muzzle.Muzzle1.Enabled = false
script.Parent.Handle.Fire:Play()
if Part and Part.Parent:FindFirstChild("Zombie") then
Part.Parent.Zombie:TakeDamage(damage)
end
end)
end)