Hi, I’m trying to make a system where you can build in the game, after figuring out that FindPartOnRay() is depreciated I moved to raycasts, though when I try to build in game I get the following error:
Unable to cast array to Raycast params
This is the script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlaceStructure = ReplicatedStorage:WaitForChild("PlaceStructure")
local MaterialFolder = ReplicatedStorage:WaitForChild("Materials")
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local StructureFrame = script.Parent.StructureFrame
local Character = player.Character or player.Character:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Mouse = player:GetMouse()
local yAxisBuildingOffset = 5
local MaxPlaceDistance = 50
local RotateKeyIsPressed = false
local PlacingStructureDebounce = false
for _, structureButton in pairs(StructureFrame:GetChildren()) do
if structureButton:IsA("TextButton") then
structureButton.MouseButton1Down:Connect(function()
StructureFrame.Visible = false
local yOrientation = 0
local InRangeToPlace = false
local placedStructure
if PlacingStructureDebounce == false then
PlacingStructureDebounce = true
local ClientStructure = MaterialFolder: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, Character}
local hit, Position = game.Workspace:Raycast(MouseRay.Origin, MouseRay.Direction * 1000, IgnoreList)
if hit and (hit:IsA("Terrain") or hit.Name:lower() == "terrain") and (HumanoidRootPart.Position - ClientStructure.Position).Magnitude < MaxPlaceDistance then
InRangeToPlace = true
ClientStructure.BrickColor = BrickColor.new("Forest green")
else
InRangeToPlace = false
ClientStructure.BrickColor = BrickColor.new("Crimson")
end
local newAnglesCFrame = CFrame.Angles(0, math.rad(yOrientation), 0)
local NewCFrame = CFrame.new(Position.X, Position.Y + yAxisBuildingOffset, Position.Z)
ClientStructure.CFrame = NewCFrame * NewCFrame
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
RotateKeyIsPressed = true
local RotationSpeed = 3
while RotateKeyIsPressed do
wait()
if PlacingStructureDebounce == true then
yOrientation = yOrientation + RotationSpeed
end
end
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
RotateKeyIsPressed = false
end
end)
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if PlacingStructureDebounce == true then
if InRangeToPlace == true then
local StructureCFrame = ClientStructure.CFrame
placedStructure = PlaceStructure:InvokeServer(ClientStructure.Name, StructureCFrame)
if placedStructure == true then
PlacingStructureDebounce = false
ClientStructure:Destroy()
StructureFrame.Visible = true
end
end
end
end
end)
end
end)
end
end
Thanks In Advance