local s=script.Parent local Q=nil local w=Region3.new(Vector3.new(s.Position.X-s.Size.X/2,s.Position.Y+s.Size.Y/2,s.Position.Z-s.Size.Z/2),Vector3.new(s.Position.X+s.Size.X/2,s.Position.Y+4,s.Position.Z+s.Size.Z/2))local t=game.Workspace:FindPartsInRegion3(w)for s,w in pairs(t)do if w and(w.Parent and w.Parent:IsA("\084\111\111\108"))then Q=w.Parent break end end local A=s.Configurations local x={}local function M(s,Q)if A:FindFirstChild(s)then x[s]=(A:FindFirstChild(s)).Value else x[s]=Q end end M("\083\112\097\119\110\067\111\111\108\100\111\119\110",60)if Q then Q.Parent=game.ServerStorage while true do local w=Q:Clone()local t=w:FindFirstChild("\072\097\110\100\108\101")w.Parent=game.Workspace local A=true local M M=w.AncestryChanged:connect(function()if t then t.Anchored=false end A=false M:disconnect()end)if t then t.CFrame=(s.CFrame+Vector3.new(0,t.Size.Z/2+1,0))*CFrame.Angles(-math.pi/2,0,0)t.Anchored=true end while A do if t then t.CFrame=t.CFrame*CFrame.Angles(0,0,math.pi/60)end wait()end wait(x.SpawnCooldown)end end

local spawner = script.Parent
local tool = nil
local region = Region3.new(Vector3.new(spawner.Position.X - spawner.Size.X/2, spawner.Position.Y + spawner.Size.Y/2, spawner.Position.Z - spawner.Size.Z/2),
   Vector3.new(spawner.Position.X + spawner.Size.X/2, spawner.Position.Y + 4, spawner.Position.Z + spawner.Size.Z/2))
local parts = game.Workspace:FindPartsInRegion3(region)
for _, part in pairs(parts) do
	if part and part.Parent and part.Parent:IsA("Tool") then
		tool = part.Parent
		break
	end
end

local configTable = spawner.Configurations
local configs = {}
local function loadConfig(configName, defaultValue)
	if configTable:FindFirstChild(configName) then
		configs[configName] = configTable:FindFirstChild(configName).Value
	else
		configs[configName] = defaultValue
	end
end

loadConfig("SpawnCooldown", 60)

if tool then
	tool.Parent = game.ServerStorage
	
	while true do
		-- put tool on pad
		local toolCopy = tool:Clone()
		local handle = toolCopy:FindFirstChild("Handle")
		toolCopy.Parent = game.Workspace
		local toolOnPad = true
		local parentConnection
		parentConnection = toolCopy.AncestryChanged:connect(function()
			if handle then handle.Anchored = false end
			toolOnPad = false
			parentConnection:disconnect()
		end)
		if handle then
			handle.CFrame = (spawner.CFrame + Vector3.new(0,handle.Size.Z/2 + 1,0)) * CFrame.Angles(-math.pi/2,0,0)
			handle.Anchored = true
		end
		-- wait for tool to be removed
		while toolOnPad do 
			if handle then
				handle.CFrame = handle.CFrame * CFrame.Angles(0,0,math.pi/60)
			end
			wait() 
		end
		
		-- wait for cooldown
		wait(configs["SpawnCooldown"])		
	end
	
end


