Cool House choosing system

Hi there. I am SpacePyro. I am working on a project that is undisclosable for now, but I made a cool house choosing system at that time.
Since it’s really simple but learnable, I decided to post it here.

How I made it:-
Basically, every house which has the tag Houses(Tag Service link) on it, gets selected. Every house is put in a table and when a player clicks left or right, it table.finds and applies a function to it which tweens the player’s camera.
It even has a system that after another player chooses a house one can no longer play it and it no longer appears in the scrolling.
And after you click play, it teleports you to a part that you choose.

The Game:- ChooseHouse.rbxl (41.0 KB)

The main local script:-

local yes = script.Parent.StartGui.Yes
local no = script.Parent.StartGui.No
local CollectionService = game:GetService("CollectionService")
local TweenService = game:GetService("TweenService")
local Player = game.Players.LocalPlayer

local MovingTween
local ChooseHouseMain = game.ReplicatedStorage.ChooseHouse
local ChooseHouseFrame = script.Parent.ChooseHouseFrame
local Camera = game.Workspace.CurrentCamera
local HouseText = script.Parent.ChooseHouseFrame.HouseName
local PlayButton = script.Parent.ChooseHouseFrame.Play
local Info = TweenInfo.new(
	0.1
)
local ChooseHouse = function()
	local Houses = CollectionService:GetTagged("Houses")
	local HousesAvailable = {}
	local ConnectionTable = {}
	for i,v in pairs(Houses) do
		local Player = v:FindFirstChild("Player")
		if Player.Value == nil then
			table.insert(HousesAvailable, v)
			local Connection
			Connection = Player:GetPropertyChangedSignal("Value"):Connect(function()
				if Player.Value ~= nil then
					table.remove(HousesAvailable, table.find(HousesAvailable, v))
					table.remove(ConnectionTable, table.find(ConnectionTable, Connection))
					Connection:Disconnect()
				end
			end)
			table.insert(ConnectionTable, Connection)
		end
	end
	ChooseHouseFrame.Visible = true
	local CurrentHouse = 1
	local LastHouse = table.getn(HousesAvailable)
	local ChangeHouseCamera = function()
		Camera.CameraType = Enum.CameraType.Scriptable
		if MovingTween ~= nil then
			MovingTween:Cancel()
		end
		local HouseCamera = HousesAvailable[CurrentHouse]:FindFirstChild("Camera")
		local properties = {
			CFrame = HouseCamera.CFrame
		}
		local Tween = TweenService:Create(Camera, Info, properties)
		MovingTween = Tween
		Tween:Play()
		HouseText.Text = HousesAvailable[CurrentHouse].Name
	end
	ChangeHouseCamera()
	local LeftConnect = ChooseHouseFrame.Left.MouseButton1Click:Connect(function()
		if CurrentHouse > 1 then
			CurrentHouse = CurrentHouse - 1 
		elseif CurrentHouse == 1 then
			CurrentHouse = table.getn(HousesAvailable)
		else 
			CurrentHouse = 1
		end
		ChangeHouseCamera()
	end)
	local RightConnect = ChooseHouseFrame.Right.MouseButton1Click:Connect(function()
		if CurrentHouse ~= table.getn(HousesAvailable) then
			CurrentHouse = CurrentHouse + 1 
		elseif CurrentHouse == table.getn(HousesAvailable) then
			CurrentHouse = 1
		else 
			CurrentHouse = 1
		end
		ChangeHouseCamera()
	end)
	table.insert(ConnectionTable, RightConnect)
	table.insert(ConnectionTable, RightConnect)
	local PlayConnect = PlayButton.MouseButton1Click:Connect(function()
		local Character = Player.Character
		if Character then
			if HousesAvailable[CurrentHouse]:FindFirstChild("Player").Value == nil then 
				ChooseHouseFrame.Visible = false
				if MovingTween ~= nil then
					MovingTween:Cancel()
				end
				Character:SetPrimaryPartCFrame(HousesAvailable[CurrentHouse].InsidePart.Value.CFrame)
				Camera.CameraType = Enum.CameraType.Custom
				ChooseHouseMain:FireServer(HousesAvailable[CurrentHouse]:FindFirstChild("Player"))
				for i,v in pairs(ConnectionTable) do
					v:Disconnect()
				end
				ConnectionTable = nil
			end

		end
	end)
	table.insert(ConnectionTable, PlayConnect)
end

local CloseGui = function()
	script.Parent.StartGui.Visible = false
end

no.MouseButton1Click:Connect(function()
	CloseGui()
end)
yes.MouseButton1Click:Connect(function()
	CloseGui()
	ChooseHouse()
end)
ChooseHouseMain.OnClientEvent:Connect(function()
	script.Parent.StartGui.Visible = true
end)

Let me know if I made any mistakes and if anyone new is seeing this, I hope you learn something.
Regards, SpacePyro. :smiley:

5 Likes

I think this need to go into #resources:community-resources not here

1 Like

Guess you’ve to put it in #resources:community-resources , and i see many other Developers agreeing to put this in community resources.

1 Like