For no explicable reason, it just crashes. No loops or anything obvious
--[[SETTINGS]]--
damage = 30 -- Set this to how much damage you want the gun to do
RPM = 600 -- How many rounds a minute can the gun fire?
ammo = 10 -- How much ammo in a clip do you want?
ammostore = 100 -- How many stored rounds do you want?
reload = "r" -- Change this to what button you want to use to reload
reloadtime = 2 -- Set this to how long you want to take to reload
--[[SETTINGS/]]--
-- Weld script by SCARFACIAL (I'm lazy and this is a good script)
local Welds = {}
local Handle = script.Parent:WaitForChild("Handle")
for _,Part in pairs(script.Parent:GetChildren()) do
if Part:IsA("BasePart") and Part ~= Handle then
local Weld = Instance.new("Weld")
Weld.C1 = Part.CFrame:toObjectSpace(Handle.CFrame)
Welds[Weld] = Part
Part.Anchored = false
Part.CanCollide = false
end
end
Handle.Anchored = false
local function ApplyWelds()
for Weld, Part in pairs(Welds) do
Weld.Part0 = Handle
Weld.Part1 = Part
Weld.Parent = game:FindFirstChild("JointsService") or Handle
end
end
script.Parent.AncestryChanged:connect(ApplyWelds)
--End of weld
local tool = script.Parent
local main = script.Parent.Main
local user
reloading = false
local firingrate = 60 / RPM
local canfire = true
auto = false
tool.Equipped:connect(function(mouse)
print("Equipped")
user = tool.Parent
if script.Parent:FindFirstChild("ammo") == false then
print("There ain't no ammo vals! better make 'ne")
local a = Instance.new("NumberValue", script.Parent)
a.Name = "ammo"
a.Value = ammo
local b = Instance.new("NumberValue", script.Parent)
b.Name = "storedammo"
b.Value = ammostore
end
mouse.Button1Down:connect(function()
print("I should fire now")
auto = true
while auto == true do
print("I can fire now")
if canfire == false and reloading == false then return end
print("I love donkeys")
canfire = false
if ammo > 0 then
ammo = ammo - 1
print(ammo .. " shots left")
-- Mah first ray evar
local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit*300)
local hit, position = game.Workspace:FindPartOnRay(ray, user)
print(position)
print(ammo .. " shots left")
print(hit) -- This is used for debugging
local hitted = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid")
if hitted then
hitted:TakeDamage(damage)
wait(firingrate)
canfire = true
else
print("You have no ammo.")
end
mouse.Button1Up:connect(function()
print("Button is up")
auto = false
end)
--Offending function
local CAS = game:GetService("ContextActionService")
function reloadGun(name, state, input)
if state == Enum.UserInputState.Begin then
print("key has been pressed")
if ammo < 10 and ammostore > 10 then
reloading = true
local difference = ammo - 10
ammo = ammo + difference
print(ammo .. " " .. difference)
ammostore = ammostore - difference
print(ammostore)
wait(reloadtime)
reloading = false
else
print("No ammo left! Da fuzz home boi! Da fuzz")
end
end
end
CAS:BindAction("ReloadGun", reloadGun, true, Enum.KeyCode.R, Enum.KeyCode.ButtonX)
end
end
end
)
end
)

2 comments
You do know that most of us are too lazy to fix scripts as long as these.
Especially when it is not tabbed correctly and looks like a mess at places...