Can you add print here?
print("e")
local objectName = item:GetAttribute("ItemName")
print(objectName)
clientPlacer:ChangeObject(player, objectName)
Can you add print here?
print("e")
local objectName = item:GetAttribute("ItemName")
print(objectName)
clientPlacer:ChangeObject(player, objectName)
I will try so, i’ll edit this post once i do so
So that script is fine. It has to be the other 2 snippets.
The only other thing I can think of is second self
in
self:PreparePreviewModel(objects:FindFirstChild(self.SelectedObject))
does not reference ClientPlacer
. Try replacing with objectName
self:PreparePreviewModel(objects:FindFirstChild(objectName))
Nope, same problem, it does not fix it.
bump once again once again
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:
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 →
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.
Ive tried discord servers, chatgpt but failed.
I’m sending this early in the morning, but where is your “self” set in the script? And what is it set to?
This is a module script, self does not need to be initialized
Well i’ve initialized it as so:
function ClientPlacer.new(plot: Model)
local self = setmetatable(
{Plot = plot,
Preview = nil,
SelectedObject = "Conveyor",
Rotation = 0,
}, ClientPlacer)
self:InitRenderPreview()
ContextActionService:BindAction(PLACE_ACTION,
function(...) self:TryPlaceBlock(...) end,
false,
Enum.UserInputType.MouseButton1)
ContextActionService:BindAction(ROTATE_ACTION,
function(...) self:RotateBlock(...) end,
false,
Enum.KeyCode.R
)
ContextActionService:BindAction(DELETE_ACTION,
function(...) self:TryDeleteBlock(...) end,
false,
Enum.KeyCode.X
)
return self
end
Are you re-running the :PreparePreview once the SelectedObject is changed?
Yes i am changing it.
101010101001010111011
Can I see the script snippet that moves the preview block?
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
Make sure you check if the self.Preview exists before attempting to use :PivotTo()!
Edit: If rotation does not work, use math.rad(self.Rotation)
Okay, i tried it out and self.Preview exists before:PivotTo() but it’s not the right one, it should be ‘ConveyorTurn’ but it’s still ‘Conveyor’
Try re- running the :PreparePreviewModel function at the start of the :RenderPreview func
That just broke it even more lol.
Hang on: RenderPreview is not the problem, PrepareRenderPreview is.
How did it break in which way? Was it like a duplication issue or just a lag issue?
Is the :PrepareRenderPreview the :PreparePreviewModel func?