-- Functions --

local function setUp()
	closedGoal = {Size = Block.Size, Position = Block.Position}
	
	local smallSize = Vector3.new((Block.Size.X), (0.05), (Block.Size.Z))
	--local smallPosition = Vector3.new((Block.Position.X), (Block.Position.Y - Block.CFrame.UpVector * Block.Size.Y * -0.5), (Block.Position.Z))
	local smallPosition = Block.Position + Block.CFrame.UpVector * Block.Size.Y * 0.5
	openGoal = {Size = smallSize, Position = smallPosition}
end

local function getProximityPrompts()
	for index, child in pairs(ProximityPrompts:GetChildren()) do
		if child:IsA("ObjectValue") then
			local prompt = child.Value
			if prompt:IsA("ProximityPrompt") then
				table.insert(proximityPrompts, prompt)
			end
		end
	end
end

local function tweenTo(goal)
	if tween then
		tween:Destroy()
	end
	
	local duration = math.abs((Block.Size.Y - goal.Size.Y) / shrinkSpeed)
	local tweenInfo = TweenInfo.new(duration, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
	tween = TweenService:Create(Block, tweenInfo, goal)
	tween:Play()
	if isOpen then
		isOpen = false
	else
		isOpen = true
	end
end

local function isOnValidTeam(player)
	local playerTeamColor = player.TeamColor
	local isValid
	
	for index, objectValue in pairs(teamColorObjectValues) do
		if objectValue.Value == playerTeamColor then
			isValid = true
		end
	end
	
	return isValid
end

local function onTriggered(player)
	if not isOnValidTeam(player) then return end
	if isOpen then
		tweenTo(closedGoal)
	else
		tweenTo(openGoal)
	end
end
