Building System Won't Work

This code is supposed to make a building system, which places wood and stone walls

Local Script in MainGui:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlaceStructure = ReplicatedStorage:WaitForChild("PlaceStructure")
local Structures = ReplicatedStorage:WaitForChild("Structures")

local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local StructureFrame = script.Parent.StructureFrame
local char = player.Character or player.Character:Wait()
local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")

local mouse = player:GetMouse()

local yBuildingOffset = 5
local maxPlacingDistance = 50
local rKeyIsPressed = false
local placingStructure = false

for _, structureButton in pairs(StructureFrame:GetChildren()) do
	if structureButton:IsA("TextButton")  then
		structureButton.MouseButton1Up:Connect(function()
			StructureFrame.Visible = false
			local yOrientation = 0
			local goodToPlace = false
			local placedStructure
			
			if placingStructure == false then
				placingStructure = true
				
				local clientStructure = Structures:FindFirstChild(structureButton.Name):Clone()
				clientStructure.BrickColor = BrickColor.new("Forest green")
				clientStructure.Material = "Neon"
				clientStructure.CanCollide = false
				clientStructure.Parent = game.Workspace
				
				local startingCFrame = CFrame.new(0, -2, -15)
				clientStructure.CFrame = HumanoidRootPart.CFrame:ToWorldSpace(startingCFrame)
				
				RunService.RenderStepped:Connect(function()
					local mouseRay = mouse.UnitRay
					local castRay = Ray.new(mouseRay.Origin, mouseRay.Direction * 1000)
					local ignoreList = {clientStructure, char}
					local hit, position = workspace:FindPartOnRayWithIgnoreList(castRay, ignoreList)
					
					if hit and hit.Name:lower() == "terrain" and (HumanoidRootPart.Position - clientStructure.Position).Magnitude < maxPlacingDistance then
						goodToPlace = true
						clientStructure.BrickColor = BrickColor.new("Forest green")
					else
						goodToPlace = false
						clientStructure.BrickColor = BrickColor.new("Crimson")
					end
					
					local newAnglesCFrame = CFrame.Angles(0, math.rad(yOrientation), 0)
					local newCFrame = CFrame.new(position.X, position.Y + yBuildingOffset, position.z)
					clientStructure.CFrame = newCFrame * newAnglesCFrame
					
				end)
				
				UIS.InputBegan:Connect(function(input)
					if input.Keycode == Enum.KeyCode.R then
						rKeyIsPressed = true
						
						local rotationSpeed = 5
						while rKeyIsPressed do
							wait()
							if placingStructure == true then
								yOrientation = yOrientation * rotationSpeed
							end
						end
					end
				end)
				
				UIS.InputEnded:Connect(function(input)
					if input.KeyCode == Enum.KeyCode.R then
						rKeyIsPressed = false
					end
				end)
				
				UIS.InputBegan:Connect(function(input)
					if input.UserInputType == Enum.UserInputType.MouseButton1 then
						if placingStructure == true then
							if goodToPlace == true then
								local structureCFrame = clientStructure.CFrame
								placedStructure = PlaceStructure:InvokeServer(clientStructure.Name, structureCFrame)
								
								if placedStructure == true then
									placingStructure = false
									clientStructure:Destroy()
									structureFrame.Visible = true
								end
							end
						end
					end
				end)
			end
		end)
	end
end

Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlaceStructure = ReplicatedStorage:WaitForChild("PlaceStructure")
local Structures = ReplicatedStorage:WaitForChild("Structures")

PlaceStructure.OnServerInvoke = function(player, structureName, structureCFrame)
	
	local crafted
	local realStructure = Structures:FindFirstChild((structureName)):Clone()
	
	if realStructure then
		realStructure.CFrame = structureCFrame
		realStructure.Parent = game.Workspace
		crafted = true
	else
		crafted = false
	end
	
	return crafted
end

Problem: It will not do ANYTHING.

Thanks for any help!

mind telling what TYPES of warnings?

1 Like

It doesn’t come up anymore but the building still won’t work.

I’ll reccomend you add print("something") after each :Connect() and If, to find where your script breaking.

1 Like

If things were breaking, would it be notified in the console (output) ?

If things were broken, you won’t see printed text, for example: print(“THIS”) → broken if you don’t see THIS in output. Until you will see printed messsages - script is ok during that moments.