--dont change any thing beside the  these numbers--
--to change explosion force go to CannonBall script--
----------------------------------------------------------------------------------------------------------------------------------------------------



	
	local missile = Instance.new("Part")

	local barrel

	if gunOne == true then
		barrel = gunBarrelOne
		gunOne = true
	
	end
	
	local spawnPos = barrel.CFrame * Vector3.new(5, 0, 0)

	local dx = math.random(50-cannonAcc,50+cannonAcc)
	local dy = math.random(targetRange-5,targetRange+5)
	local dz = math.random(0-cannonAcc,0+cannonAcc)
	local mag = math.random(power,power)

	local v = barrel.CFrame:vectorToWorldSpace(Vector3.new(mag + dx,dy,dz))
	
	local missile = cannonBall:clone()

	missile.Position = spawnPos
	missile.Velocity = v


	
	local new_script = script.Parent.CannonBall:clone()
	new_script.Disabled = false
	new_script.Parent = missile

	local creator_tag = Instance.new("ObjectValue")
	creator_tag.Value = player
	creator_tag.Name = "creator"
	creator_tag.Parent = missile
	


	missile.Parent = game.Workspace



		local effect=script.Parent.Parent.Effect
		local fire = effect.Fire
		local smoke1 = effect.Smoke
		local smoke2 = effect.Smoke1

		fire.Enabled = true
		smoke1.Enabled = true
		smoke2.Enabled = true
		wait(0.3)
		fire.Enabled = false
		wait(0.5)
		smoke1.Enabled =false
		smoke2.Enabled = false
		


end

function onClicked()
local reloadTime = 10-- +1
	if debounce == false then
		debounce = true
		switch.BrickColor = BrickColor.new(21)
		fire(player)
		wait(reloadTime)

		debounce = false
		switch.BrickColor = BrickColor.new(37)
	end
end


script.Parent.ClickDetector.MouseClick:connect(onClicked)


