Hi there! I’ve been using some guides to build up a placement system, and now there will be multiple objects to build with, however, when selecting a different item, it bugs out.
Here’s the clip:
Every rendered frame, it prints out the self.Preview value (the object that is following my mouse in the clip). As you can see, when i press the button, ‘e’ is printed and it should start printing ‘ConveyorTurn’ but it does not.
I use an attribute on each item inside of the frame as shown here:
Here are some code snippets that might help solve the problem:
-- The GUI handler (or whatever else it could be called)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local placableObjects = ReplicatedStorage.Objects
local clientPlacer = require(player.PlayerScripts.ClientPlacer)
local gui = script.Parent
local selectList = gui.SelectFrame.SelectList
for _, item in selectList:GetChildren() do
if item:IsA("Frame") then
item.ItemName.MouseButton1Click:Connect(function()
print("e")
local objectName = item:GetAttribute("ItemName")
clientPlacer:ChangeObject(player, objectName)
end)
end
end
-- Client placer pt.1 (renders the object that moves wherever my mouse points at)
function ClientPlacer:PreparePreviewModel(model: Model)
if self.Preview then
self.Preview:Destroy()
end
self.Preview = model:Clone()
local boxOutline = boxOutlineTemplate:Clone()
boxOutline.Adornee = self.Preview
boxOutline.Parent = self.Preview
for _, part in self.Preview:GetDescendants() do
if part:IsA("BasePart") then
part.CanCollide = false
part.CanQuery = false
part.Transparency = 0.5
end
end
self.Preview.Parent = workspace
end
-- Client placer pt.2 (where the object value is changed)
function ClientPlacer:ChangeObject(player: Player, objectName: string)
local objects = ReplicatedStorage:WaitForChild("Objects")
self.SelectedObject = objectName
self:PreparePreviewModel(objects:FindFirstChild(self.SelectedObject))
end
Okay, I’ve seen all of your bumps now and I just have to respond I guess:
I don’t understand how I am supposed to help?
In the guidelines for “Scripting Support” it states that you have to be able to answer these 3 questions:
What do you want to achieve
What seems to be the issue
What have you tried so far to fix it
You want your system fixed but you did not explain where the issue most likely lies. I do not think many people want to go around searching for issues that might be outside of their scope →
Is this the only code related to the area of problem occurance?
What have you already tried to fix the issue?
Where exactly is the issue? What does not work and where is the code related to it?
I am here to help, so please answer the questions and stop bumping this post.
So basically, i’ve ruled out that these two snippets hold the issue:
-- Client placer pt.1 (renders the object that moves wherever my mouse points at)
function ClientPlacer:PreparePreviewModel(model: Model)
if self.Preview then
self.Preview:Destroy()
end
self.Preview = model:Clone()
local boxOutline = boxOutlineTemplate:Clone()
boxOutline.Adornee = self.Preview
boxOutline.Parent = self.Preview
for _, part in self.Preview:GetDescendants() do
if part:IsA("BasePart") then
part.CanCollide = false
part.CanQuery = false
part.Transparency = 0.5
end
end
self.Preview.Parent = workspace
end
-- Client placer pt.2 (where the object value is changed)
function ClientPlacer:ChangeObject(player: Player, objectName: string)
local objects = ReplicatedStorage:WaitForChild("Objects")
self.SelectedObject = objectName
self:PreparePreviewModel(objects:FindFirstChild(self.SelectedObject))
end
Adding on, i want it so where you select a new item, the previous one destroys and now follows my mouse, but it does not.
function ClientPlacer:RenderPreview()
local cast = castMouse()
if cast and cast.Position then
local cf = CFrame.new(cast.Position) * CFrame.Angles(0, self.Rotation, 0)
self.Preview:PivotTo(cf)
print(self.Preview)
local size = self.Preview:GetExtentsSize()
self.Preview.BoxOutline.Color3 =
if placementValidator.WithinBounds(self.Plot, size, cf) and
placementValidator.NotIntersectingObject(self.Plot, size, cf) then
Color3.new(0, 1, 1)
else
Color3.new(1, 0, 0)
end
end