I know this is a stupid question, but this problem has been pretty annoying lately. The script works perfectly but I don't know why its filling my output with errors. There is nothing wrong with my script.
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.StructuresFrame
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()
for _, partsInStructure in pairs(clientStructure:GetChildren()) do
if partsInStructure:IsA("Part") or partsInStructure:IsA("UnionOperation") then
partsInStructure.BrickColor = BrickColor.new("Cyan")
partsInStructure.Material = Enum.Material.Wood
partsInStructure.Transparency = 0.6
partsInStructure.CanCollide = false
end
end
clientStructure.Parent = workspace
local startingCFrame = CFrame.new(0, -2, -15)
clientStructure:SetPrimaryPartCFrame(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:FindFirstChild("Main").Position).Magnitude < maxPlacingDistance then
goodToPlace = true
for _, StructureParts in pairs(clientStructure:GetChildren()) do
if StructureParts:IsA("Part") or StructureParts:IsA("UnionOperation") then
StructureParts.BrickColor = BrickColor.new("Cyan")
end
end
else
goodToPlace = false
for _, StructureParts in pairs(clientStructure:GetChildren()) do
if StructureParts:IsA("Part") or StructureParts:IsA("UnionOperation") then
StructureParts.BrickColor = BrickColor.new("Crimson")
end
end
end
local newAnglesCFrame = CFrame.Angles(0, math.rad(yOrientation), 0)
local newCFrame = CFrame.new(position.X, position.Y + yBuildingOffset, position.Z)
clientStructure:SetPrimaryPartCFrame(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:GetPrimaryPartCFrame()
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
