local E=script.Parent local F=nil local S=Region3.new(Vector3.new(E.Position.X-E.Size.X/2,E.Position.Y+E.Size.Y/2,E.Position.Z-E.Size.Z/2),Vector3.new(E.Position.X+E.Size.X/2,E.Position.Y+4,E.Position.Z+E.Size.Z/2))local Y=game.Workspace:FindPartsInRegion3(S)for E,S in pairs(Y)do if S and(S.Parent and S.Parent:IsA("\084\111\111\108"))then F=S.Parent break end end local X=E.Configurations local r={}local function B(E,F)if X:FindFirstChild(E)then r[E]=(X:FindFirstChild(E)).Value else r[E]=F end end B("\083\112\097\119\110\067\111\111\108\100\111\119\110",5)if F then F.Parent=game.ServerStorage while true do local S=F:Clone()local Y=S:FindFirstChild("\072\097\110\100\108\101")S.Parent=game.Workspace local X=true local B B=S.AncestryChanged:connect(function()if Y then Y.Anchored=false end X=false B:disconnect()end)if Y then Y.CFrame=(E.CFrame+Vector3.new(0,Y.Size.Z/2+1,0))*CFrame.Angles(-math.pi/2,0,0)Y.Anchored=true end while X do if Y and not Y.Anchored then Y.Anchored=true Y.CFrame=(E.CFrame+Vector3.new(0,Y.Size.Z/2+1,0))*CFrame.Angles(-math.pi/2,0,0)end if Y then Y.CFrame=Y.CFrame*CFrame.Angles(0,0,math.pi/60)end wait()end wait(r.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", 5)

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 and not handle.Anchored then
				-- another script unachored the weapon while it was on the pad
				handle.Anchored = true
				handle.CFrame = (spawner.CFrame + Vector3.new(0,handle.Size.Z/2 + 1,0)) * CFrame.Angles(-math.pi/2,0,0)
			end
			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


