I am trying to make a model placement system where you select a model and then it shows up allowing you to place it anywhere. I’ve searched as much as I can but I can’t find anything.
This is a vide of my issue, as you can see it is slowly descending into the void.
Here is my script:
game.ReplicatedStorage.RemoteEvents.DecoySpawn.OnServerEvent:Connect(function(player, propName)
game.ReplicatedStorage.Placing.Value = true
game.ReplicatedStorage.PropName.Value = propName
local clone = game.ReplicatedStorage.Props:FindFirstChild(propName):Clone()
for i, v in pairs(clone:GetDescendants()) do
if v then
if v:IsA("Part") then
v.CanCollide = false
v.Transparency = 0.5
end
end
end
while true do
wait(0.01)
if game.ReplicatedStorage.Placing.Value == true then
local movePart = clone:FindFirstChild("MovePart")
local character = player.Character
local HumanoidRootPart = character:FindFirstChild("HumanoidRootPart")
clone.Parent = game.Workspace.Following
movePart.CFrame = HumanoidRootPart.CFrame * CFrame.new(0,0,-30) -- This might be where the error is occuring.
else
break
end
end
end)
So the only part I anchored was the PrimaryPart of the model which is labeled as “movePart” in the script. Everything else is welded together to the movePart.
Maybe you’re right, but he can still try and see if makes a difference. I made a placement system like his one before and it did not sink into the ground even when CanCollide was false.
I tried what you said by making CanCollide false and the model flung out of the map. I also would not like it to be on because there will be other stuff on the map other than what you place.
Ok so I took a look at some old code I made, and the only two difference I could notice was that first, I used model:PivotTo() for models, and that secondly, I used a RenderStepped:Connect() instead of a while true do.
I also didn’t re-get the part im moving, the character, and the HRP, and instead just kept their references.
The models position isnt changed with the mouse. My goal is to make it directly infront of your character so you can align it perfectly how you want. But yes, MovePart is the part I am moving, its also the PrimaryPart in the model.
I’ve never tried using PivotTo() so is this how you were saying I should use it? clone:PivotTo(CFrame.new(HumanoidRootPart.CFrame.Position.X, HumanoidRootPart.CFrame.Position.Y, HumanoidRootPart.CFrame.Position.Z - 30))
Are you using Welds or WeldConstraints? I think the offset of Weld’s change when you set a parts CFrame. WeldConstraints may fix your issue, or maybe PivotTo would work with Welds.
On the WeldConstraints Dev docs:
“If a welded part’s CFrame is updated, that part will move and all of the connected parts will also move, ensuring they maintain the same offset as when the weld was created.”
@greenboo5 probably identified the correct issue, in which case simply doing PivotTo should work, as PivotTo moves the entire model, not just a single basepart. (If it doesn’t work, you could always remove the welds. That should absolutely work considering I’ve literally done that)