Hello! I am working on an FPS Framework, and I have been having an error while working on a reloading system. The error is: [22:24:36.246 - Script timeout: exhausted allowed execution time
Please help me with this! I have no idea what’s going on here!
My Script:
if shooting == false and WeaponData.Ammo ~= 0 then
shooting = true
local muzzle = WeaponInHand:WaitForChild("Muzzle")
local ray = Ray.new(muzzle.CFrame.p, (mouse.Hit.p-muzzle.CFrame.p).unit * 999)
local part, pos = workspace:FindPartOnRayWithIgnoreList(ray, {cam,char,ignore})
local damage = 0
muzzle:WaitForChild("Fire"):Play()
recoilcf = WeaponData.ShootCFrame
if part then
if part.Parent:FindFirstChild("Humanoid") then
if part.Name == "Head" then
damage = WeaponData.HeadDamage
else
damage = WeaponData.Damage
end
end
Events.Shoot:FireServer(part,pos,damage) --sends value(s) to server
end
WeaponData.Ammo = WeaponData.Ammo -1
print(WeaponData.Ammo)
wait(60/WeaponData.ShootRate)
shooting = false
end
end
It looks like you need a wait after this conditional. If true doesn’t pass for both evaluations for the conditional, you’re gonna run into an infinite loop.
while true do
if shooting == false and WeaponData.Ammo ~= 0 then
shooting = true
local muzzle = WeaponInHand:WaitForChild("Muzzle")
local ray = Ray.new(muzzle.CFrame.p, (mouse.Hit.p-muzzle.CFrame.p).unit * 999)
local part, pos = workspace:FindPartOnRayWithIgnoreList(ray, {cam,char,ignore})
local damage = 0
muzzle:WaitForChild("Fire"):Play()
recoilcf = WeaponData.ShootCFrame
if part then
if part.Parent:FindFirstChild("Humanoid") then
if part.Name == "Head" then
damage = WeaponData.HeadDamage
else
damage = WeaponData.Damage
end
end
Events.Shoot:FireServer(part,pos,damage) --sends value(s) to server
end
WeaponData.Ammo = WeaponData.Ammo -1
print(WeaponData.Ammo)
wait(60/WeaponData.ShootRate)
shooting = false
end
-- add wait here --
end