I am making a basic furniture placement system for my game, and I am having trouble with hiding the selection box (for previewing) after the player has placed the structure.
After the player has placed the structure, it still shows the SelectionBox, but I intended to make it disappear when the player places the structure.
I am having the particular trouble in Line #35 of the Script for the server.
Script for the server:
-- Script local ReplicatedStorage = game:GetService("ReplicatedStorage") local MousePositionEvent = Instance.new("RemoteEvent") MousePositionEvent.Name = "MousePositionEvent" MousePositionEvent.Parent = ReplicatedStorage local MouseClickEvent = Instance.new("RemoteEvent") MouseClickEvent.Name = "MouseClickEvent" MouseClickEvent.Parent = ReplicatedStorage -- Preview the placement local function PreviewPlace(Owner, PositionBase, StructureBase) StructureBase.UserOwner.Value = Owner.Name -- Assign Owner local Position = CFrame.new(PositionBase) StructureBase:SetPrimaryPartCFrame(Position) -- Move the structure -- Make it look like it's being previewed local Selection = StructureBase.SelectionBox Selection.Color3 = Color3.new(0, 255, 0) Selection.Transparency = 0 end MousePositionEvent.OnServerEvent:Connect(PreviewPlace) -- Mouse position event listener -- Place the structure when the user clicks local function Place(Owner, PositionBase, StructureBase, DestinationFolder) local NewStructure = StructureBase:Clone() NewStructure.Parent = DestinationFolder NewStructure.UserOwner.Value = Owner.Name -- Assign Owner -- Hide the selection box after player has placed structure [I AM HAVING TROUBLE WITH THIS!] local Selection = StructureBase.SelectionBox Selection.Transparency = 1 print(Owner.Name .. " has ended placing a " .. NewStructure.Name .. "!") end MouseClickEvent.OnServerEvent:Connect(Place)
Script for the client:
-- LocalScript local ReplicatedStorage = game:GetService("ReplicatedStorage") local MousePositionEvent = ReplicatedStorage:WaitForChild("MousePositionEvent") local MouseClickEvent = ReplicatedStorage:WaitForChild("MouseClickEvent") local Players = game:GetService("Players") local Player = Players.LocalPlayer local Mouse = Player:GetMouse() local MouseCFrame local MousePosition local SelectedStructure = game.Workspace.OakWoodBeam -- The selected Strukchur local SelectedStructureAmount = 3 local DestDir = game.Workspace -- Destination Folder for placed structures local Placing = true -- Placing Status Mouse.Button1Down:Connect(function() SelectedStructureAmount = SelectedStructureAmount - 1 if (SelectedStructureAmount == 0) then Placing = false end MouseClickEvent:FireServer(MousePosition, SelectedStructure, DestDir) -- Trigger function place() in server print (Placing) print (SelectedStructureAmount) end) -- Updates the mouse CFrame, and updates server about it function UpdatePosition() MouseCFrame = Mouse.Hit MousePosition = MouseCFrame.p if (SelectedStructureAmount >= 1 and Placing == true) then -- If structure amount is not yet 0 MousePositionEvent:FireServer(MousePosition, SelectedStructure) return true else if (Placing == false) then -- Place the Structure when the user clicks return false end end end -- Game loop [CLIENT] while true do UpdatePosition() --print (Placing) wait() end
How would I fix it?
The selection box should be handled locally, as it's something only the player that it's relevant to should see. This would also significantly make the code cleaner and easier to manage.