Im trying to make a placement system using UIS:GetMouseLocation() but when i try to place a block i get lots of errors, any help?
RunService.RenderStepped:Connect(function()
local mouse = UIS:GetMouseLocation()
local mouseRay = camera:ScreenPointToRay(mouse.Y, mouse.X)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {clientStructure, char}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local rayResult = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 20, raycastParams)
if rayResult then
goodtoplace = true
clientStructure.BrickColor = BrickColor.new("Forest green")
print(mouseRay.Direction)
else
clientStructure.BrickColor = BrickColor.new("Crimson")
end
local newAnglesCFrame = CFrame.Angles(0, math.rad(yOrientation), 0)
local newCFrame = CFrame.new(rayResult.Position.X, rayResult.Position.Y, rayResult.Position.Z)
clientStructure.CFrame = newCFrame
end)
end
Full Code:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlaceStructure = ReplicatedStorage:WaitForChild("PlaceStructure")
local Blocks = ReplicatedStorage:WaitForChild("Blocks")
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local StructureFrame = script.Parent.StructureFrame
local char = player.Character or player.Character:Wait()
local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")
local yBuildingOffset = 5
local maxPlacingDistance = 50
local rPressed = false
local placingStructure = false
for _, structureButton in pairs(StructureFrame:GetChildren()) do
structureButton.MouseButton1Up:Connect(function()
local yOrientation = 0
local goodtoplace = false
local placedstructure
if placingStructure == false then
placingStructure = true
local clientStructure = Blocks:FindFirstChild(structureButton.Name):Clone()
clientStructure.BrickColor = BrickColor.new("Forest green")
clientStructure.Material = "Neon"
clientStructure.CanCollide = false
clientStructure.Parent = workspace
local startingCFrame = CFrame.new(0,-2,-15)
clientStructure.CFrame = HumanoidRootPart.CFrame:ToWorldSpace(startingCFrame)
RunService.RenderStepped:Connect(function()
local mouse = UIS:GetMouseLocation()
local mouseRay = camera:ScreenPointToRay(mouse.Y, mouse.X)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {clientStructure, char}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local rayResult = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 20, raycastParams)
if rayResult then
goodtoplace = true
clientStructure.BrickColor = BrickColor.new("Forest green")
print(mouseRay.Direction)
else
clientStructure.BrickColor = BrickColor.new("Crimson")
end
local newAnglesCFrame = CFrame.Angles(0, math.rad(yOrientation), 0)
local newCFrame = CFrame.new(rayResult.Position.X, rayResult.Position.Y, rayResult.Position.Z)
clientStructure.CFrame = newCFrame
end)
end
end)
end