Need help with part of my placement system

I’m making my placement system. This is the code that makes the wall drag where ever the players mouse moves, and that doesn’t work. it also has a rotating system. but neither of them work. the code is lengthy but you only really need to look at where the error is.

-local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Structure = ReplicatedStorage:WaitForChild("PlaceStructure")

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

local Structures = ReplicatedStorage:WaitForChild("Structures")

--Loop through GUI's

for _, StructureButton in pairs(StructureFrame:GetChildren()) do
	if StructureButton:IsA("TextButton")then
		StructureButton.MouseButton1Up:connect(function()
			
			StructureFrame.Visible = false
			
			local yOrientation = false
			local GoodToPlace = false
			local placeStructure = nil
			
			if PlacingStructure == false then
				PlacingStructure = true
				
				local clientStructure = Structures:FindFirstChild(StructureButton.Name):Clone()
				clientStructure.BrickColor = BrickColor.new("Forest green")
				clientStructure.Material = "Neon"
				clientStructure.Parent = 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:IsA("Terrain") or 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 * newCFrame
				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
								local placedStructure = placeStructure:InvokeServer(clientStructure.Name,structureCFrame)
								
								
								if placeStructure == true then
									PlacingStructure = false
									clientStructure:Destroy()
									StructureFrame.Visible = true
								end
							end
						end
					end
				end)
			end
		end)
	end
end

this is the error:

 Players.Kimathi4theWin.PlayerGui.MainGui.StructureHandler:61: invalid argument #1 to 'rad' (number expected, got boolean)  -  Client - StructureHandler:6

Thanks,

Help is appreciated!

You set yOrientation to a boolean, and in math.rad, you’re trying to convert a boolean into radians

1 Like