How could i make a Prop selection system like in Block n' Props?

What do i want to achieve? A Selection system like i Block n’ props (You will prob understand after seeing the script)

Like this:
Screenshot 2025-03-05 155030

local Props = game.ReplicatedStorage.Props:GetChildren()
local Add = script.Parent.AddPart.CD
local Remove = script.Parent.RemovePart.CD
local SpawnButton = script.Parent.SpawnPart.CD
local DisplayText = script.Parent.DisplayPart.DisplayGui.Text

local SelectedProp = 1

Add.MouseClick:Connect(function()
	if SelectedProp == 1 then
		if Props[SelectedProp]:FindFirstChildWhichIsA("Part") then
			SelectedProp += 1
			SpawnButton.MouseClick:Connect(function()
				local Part = Props[SelectedProp]:FindFirstChildWhichIsA("Part"):Clone()
				Part.Parent = workspace
			end)
		end
	end
end)

Remove.MouseClick:Connect(function()
	
end)

while true do
	task.wait()
end

I would like a reply ;-; please

Hello. There are several issues with this code, but you have the right gist on everything.

while true do
	task.wait()
end

Please do not use this. There is no reason for you to do that.

Secondly, you are using a Local Script, and attempting to spawn a part like that. This will work, although the part will only appear for the client, not for anyone else.

To circumvent this, you can use a RemoteEvent that the client fires, and the server responds by spawning that part in. You could probably also set the CFrame of the part

Here is an example

-- Localscript
local SelectedProp = 1

Add.MouseClick:Connect(function()
end) -- Do not do many if statements. It's inefficient

Remove.MouseClick:Connect(function()
end) -- Do not do many if statements. It's inefficient

local RemoteEvent = ReplicatedService:FindFirstChild("SpawnPart") -- RemoteEvent

SpawnButton.MouseClick:Connect(function()
	RemoteEvent:FireServer(SelectedProp)
end)
-- ServerScript
local RemoteEvent = ReplicatedStorage:FindFirstChild("SpawnPart")

RemoteEvent.OnServerEvent:Connect(function(playerWhoFired, SelectedProp)
	local Part = Props[SelectedProp]:FindFirstChildWhichIsA("Part"):Clone()
	Part.Parent = workspace
	Part.Position = playerWhoFired.Character.HumanoidRootPart.Position + Vector3.new(2,0,0)
end)

-- You can change this to be a model, but by doing that you'll have to change the Model.PrimaryPart.

Hope this helps!

Attually im not using a Local script.

You should not use normal scripts for UI stuff. That should be a localscript.

But im using Clickdetectors lol, the ui is just displaying

My Apologies. Then just ignore the remote event stuff, and take the code from

local Part = ...
Part.Parent = ...
Part.Position = ...

And then chuck that into the SpawnButton.MouseClick() function. Make sure that it is out of Add and Remove