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


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 enabled = true
local equipped = false
local ischarging = false
local Config = tool:FindFirstChild("Config")
local Direction = Config:FindFirstChild("Direction")
Direction.Value = "Up"

tool.Selected:connect(function(mouse)
	equipped = true
	mouse.Icon = "rbxasset://textures\\GunCursor.png"
	mouse.Button1Down:connect(function()
		if not enabled then return end
		if hum == nil then return end
		if hum.Health <= 0 then return end
		if mouse == nil then return end
		if not ischarging then
			ischarging = true
			enabled = false
			script.Parent.ReleaseProjectile:FireServer(mouse.Hit.p)
			mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
			wait(RELOAD_TIME)
			mouse.Icon = "rbxasset://textures\\GunCursor.png"
			enabled = true
			ischarging = false
		end
	end)
	mouse.KeyDown:connect(function(key)
		key = key:lower()
		if key == "q" then
			if Direction.Value == "Up" then
				Direction.Value = "Down"
			elseif Direction.Value == "Down" then
				Direction.Value = "Left"
			elseif Direction.Value == "Left" then
				Direction.Value = "Right"
			elseif Direction.Value == "Right" then
				Direction.Value = "Up"
			end
		elseif key == "e" then
			if Direction.Value == "Up" then
				Direction.Value = "Right"
			elseif Direction.Value == "Right" then
				Direction.Value = "Left"
			elseif Direction.Value == "Left" then
				Direction.Value = "Down"
			elseif Direction.Value == "Down" then
				Direction.Value = "Up"
			end
		end
	end)
end)

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


