I'm making a furniture placement system and on line 55 it doesn't work and place on the plot or at all. I'm trying to make it just place on the players plot. Please Help!
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Mouse = Player:GetMouse()
local Camera = workspace.CurrentCamera
local PlaceObject = game.ReplicatedStorage.BuildEvents.PlaceObject
local GivenPlot = game.ReplicatedStorage.BuildEvents.GivenPlot
local posX
local posY
local posZ
local YPos = Vector3.new(-1, 75, 0)
local Rot = 0
local Object
local ButtonSoil = script.Parent.ScrollingFrame.Soil.ImageButton
local CanStart = true
IsPlacing = nil
local CanPlace = nil
GivenPlot.OnClientEvent:Connect(function(plr, plt)
plot = plt
end)
local function Snap()
posX = math.floor(Mouse.Hit.X / 2 + 0.5)*2
posY = math.floor(Mouse.Hit.Y / 2 + 0.5)*2 -.5
posZ = math.floor(Mouse.Hit.Z / 2 + 0.5)*2
end
local function Placement()
if IsPlacing and CanPlace then
PlaceObject:FireServer(posX, posY, posZ, Rot, Object.Name)
IsPlacing = false
CanPlace = false
CanStart = true
Object:Destroy()
end
end
local function TopDownView()
if IsPlacing then
local playerPos = Char:FindFirstChild("HumanoidRootPart").Position
local cameraPos = playerPos + YPos
Camera.CFrame = CFrame.new(cameraPos, playerPos)
end
end
local function Movement()
if IsPlacing and CanPlace and not CanStart and Mouse.Target and Mouse.Target.Name == plot then
Mouse.TargetFilter = Object
Snap()
Object:SetPrimaryPartCFrame(CFrame.new(posX, posY, posZ) * CFrame.Angles(0, math.rad(Rot), 0))
else
return Mouse.Hit.p
end
end
local function StartPlacementSoil()
if CanStart then
Object = game:GetService("ReplicatedStorage").Soil:Clone()
Object.Parent = workspace
Mouse.Move:Connect(Movement)
IsPlacing = true
CanPlace = true
CanStart = false
Mouse.Move:Connect(Movement)
end
end
local function Rotation(input, GPE)
if IsPlacing and CanPlace and not CanStart and input.KeyCode == Enum.KeyCode.R then
Rot = Rot + 90
Object:SetPrimaryPartCFrame(Object.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(Rot), 0))
end
end
Mouse.Button1Down:Connect(Placement)
ButtonSoil.MouseButton1Click:Connect(StartPlacementSoil)
RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, TopDownView)
UIS.InputBegan:Connect(Rotation)
