This is my code, I can't figure out why it's freezing. If someone could figure out what's wrong, could they tell me what is? I think it might be the firing part because I just added it and this started happening.
--//Variables
local plr = game.Players.LocalPlayer
local tool = script.Parent.Parent
local hole = tool.Hole
local handle = tool.Handle
local debounce = true
local config = tool.Config
local range = config.Range
local dmg = config.Damage
local coolDown = config.CoolDown
local clips = config.Clips
local ammo = config.Ammo
local maxAmmo = config.MaxAmmo
local allowTracing = config.AllowTracing
local reloadTime = config.ReloadTime
local isReloading = false
local firing = false
--//Sounds
local reloadSound = tool.Handle.ReloadSound
local fireSound = tool.Handle.FireSound
local equipSound = tool.Handle.EquipSound
local emptySound = tool.Handle.EmptySound
--//Events
tool.Equipped:Connect(function(mouse)
equipSound:Play()
tool.Activated:Connect(function()
firing = true
repeat
if not isReloading then
if firing == true then
if ammo.Value > 0 then
if debounce then
--//Play sound
fireSound:Play()
--//Doesn't allow spamming
debounce = true
--//Ray Get, Set
local ray = Ray.new(hole.CFrame.p, (mouse.Hit.p - hole.CFrame.p) * range.Value)
local hit, position = workspace:FindPartOnRay(ray, plr.Character, false, true)
--//Bullet Tracing
if allowTracing.Value == true then
--//Make part
local trace = Instance.new("Part", workspace)
trace.Material = Enum.Material.Neon
trace.BrickColor = BrickColor.new("Black")
trace.CanCollide = false
trace.Anchored = true
trace.Transparency = 0.5
wait()
--//Show Direction
local distance = (hole.CFrame.p - position).magnitude
trace.Size = Vector3.new(0.2, 0.2, distance)
trace.CFrame = CFrame.new(hole.CFrame.p, position) * CFrame.new(0, 0, -distance/2)
--//Remove debris
game:GetService("Debris"):AddItem(trace, 0.1)
end
--//Hit Detection
if hit then
local humanoid = hit.Parent:FindFirstChild("Zombie")
if humanoid then
if hit.Name == "Head" then
--//Double damage on headshots
humanoid:TakeDamage(dmg.Value*2)
else
--//Normal Damage on body shots
humanoid:TakeDamage(dmg.Value)
end
end
end
ammo.Value = ammo.Value - 1
wait(coolDown.Value)
debounce = true
end
else
--//Out of ammo
-- emptySound:Play()
end end
end
--if ammo == 0 then
--firing = false
--end
mouse.Button1Up:Connect(function()
wait()
firing = false
end)
until firing == false
end)
--//Reload Event
mouse.Button1Down:Connect(function(click)
--key:lower()
--if key == "r" then
if not isReloading then
if clips.Value > 0 then
if ammo.Value == 0 then
isReloading = true
reloadSound:Play()
wait(reloadTime.Value)
ammo.Value = maxAmmo.Value
clips.Value = clips.Value - 1
isReloading = false
end
end
end
end)
end)

3 comments
Should I change "until firing == false"?
@zandefear4 Do you have a
wait()in youruntilloop?Make sure you have waits and most parts unioned, if still crashing that means it's your PC