I’m attempting to make a plot building system which allows you to build structure out of different models using a GUI, I have chosen a method of using a transparent NoCollide brick so that I can make my script detect where the plot is and for it to only build there. Though my script is not working for some reason because instead of the highlighted models going to the mouse it goes to the top of the plot model. I thought this had to do with both models which are No-collide still colliding. Could anyone help? Code:
game:GetService("RunService").Render Stepped:Connect(function()
if model ~= nil then -- checks if model has been selected
local TopOfPlot = Plot.Size.Y
local BottomOfPart = model.PrimaryPart.Position.Y - Plot.Size.Y
if BottomOfPart < TopOfPlot then
model:MoveTo(Vector3.new(Mouse.Hit.p.X, Mouse.Hit.p.Y, Mouse.Hit.p.Z))
end
end
end)
CanCollide doesn’t affect raycasts or the mouse.Hit property. You should set the Y position of the model to the correct level instead of Mouse.Hit.p.Y
The correct level is Mouse.Hit.p.y, when the mouse is moved around the model is put to the mouse. So they can place it on and level, such as on top of another part.
Try replacing this line:
model:MoveTo(Vector3.new(Mouse.Hit.p.X, Mouse.Hit.p.Y, Mouse.Hit.p.Z))
with this:
model:SetPrimaryPartCFrame(CFrame.new(Vector3.new(Mouse.Hit.p.X, Mouse.Hit.p.Y, Mouse.Hit.p.Z)))
The model must have a primary part!
This is because according to the API article on Model:MoveTo(),
If there are any obstructions where the model is to be moved to, such as Terrain
or other BasePart
s, then the model will be moved up in the Y direction until there is nothing in the way.
This isn’t working either for some reason, now with this line I have lost all movement from the object to the mouse.
https://gyazo.com/552c30deb5a0c7ba3ab220d5b653a537
This is exactly what I’m working on, a building system (You can find it under my profile on roblox). I use TweenService to animate the movement of the object I’m trying to place down. I also have a grid system so the object only animates to a new position if I enter a new grid.
Another thing you might want to try is to make a dedicated function and then bind that to renderStep with the camera as a value change. Like this:
RunService:BindToRenderStep("BuildModel", Enum.RenderPriority.Camera.Value, moveItem)