-------------------------------


local tool = script.Parent
local player = game.Players.LocalPlayer
while player.Character == nil do wait() end
local char = player.Character
while char:FindFirstChild("Humanoid") == nil do wait() end
local hum = char:FindFirstChild("Humanoid")
local mouse = player:GetMouse()

local going = false
local enabled = true
local equipped = false

function stoppedGoing(mouse)
	if going then
		going = false
		script.Parent.Stopped:FireServer()
		wait(RELOAD_TIME)
		if equipped then
			mouse.Icon = "rbxasset://textures\\GunCursor.png"
		end
		enabled = true
	end
end

tool.Selected:connect(function(mouse)
	equipped = true
	mouse.Icon = "rbxasset://textures\\GunCursor.png"
	mouse.Button1Down:connect(function()
		if hum == nil then return end
		if hum.Health <= 0 then return end
		if mouse == nil then return end
		if enabled then
			if not going then
				if mouse.Hit ~= nil then
					enabled = false
					going = true
					script.Parent.Start:FireServer(mouse.Hit.p)
					mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
				end
			end
		end
	end)
	mouse.Button1Up:connect(function()
		stoppedGoing(mouse)
	end)
end)

tool.Deselected:connect(function()
	equipped = false
	stoppedGoing(mouse)
end)


