--[[
    Client side script that requests a bomb throw if the player activates their tool outside of cooldown
]]

local Players = game:GetService("Players")

local localPlayer = Players.LocalPlayer
local mouse = localPlayer:GetMouse()

local tool = script.Parent
local fireEvent = tool:WaitForChild("Fire")
local cooldown = tool:WaitForChild("Cooldown").Value

local lastThrow = 0
tool.Activated:Connect(
	function()
		local nowTick = tick()
		if nowTick - lastThrow > cooldown then
			lastThrow = nowTick
			local character = localPlayer.Character
			if character and character.PrimaryPart then
				local origin = character.PrimaryPart.Position
				local target = mouse.Hit.p
				fireEvent:FireServer(origin, target)
			end
		end
	end
)
