Hello all. I am forwarding on behalf of my friend JSS64641. He is currently having an error with his script and would appreciate help & support. He can’t make a post himself as he hasn’t reached the max amount of hours. (Everything below is written by him)
Context:
I have a script that will let a player pick up a crate model when it is interacted with, the crate is made up of 34-42 parts (depending on how many items are loaded into the crate), one RootPart (of which is set as the PrimaryPart in the model’s properties) and one ProximityPrompt object.
Each object (excluding the RootPart and ProximityPrompt) has a WeldConstraint child, every weldconstraint is enabled and has Part0 set to it’s parent (the part in question) and Part1 set to the RootPart. (For the sake of thoroughness I have painstakingly checked each one, and yes each one is active and has the correct Part0 and Part1)
Problem:
Now everything is ready, I try to do several things:
- Move the model to HumanoidRootPart.Position
- Orient the model to HumanoidRootPart.Orientation
- Move the model n studs forwards from the HumanoidRootPart so it is not clipping into the person
Now, I have only been able to do 1) from the list above. Doing either 2) or 3) completely eludes my coding skill
I have featured below 5 solutions I have tried. I have tried other lines of code, but unfortunately those are lost (none of them worked any better than those below anyway).
Note that each solution is a standalone piece of code, and is not meant to be combined with any other solution.
local offset_x = 0
local offset_y = 0
script.Parent.Parent:MoveTo(player:FindFirstChild("HumanoidRootPart").Position)
-- moves the crate to the position of the humanoid root part, however i cannot rotate it with either :MoveTo(CFrame of humanoidroot) or :PivotTo(CFrame of humanoidroot) afterwards, nor can I figure out how to then move it n studs infront of the player
local new_CFrame = CFrame.new(player:FindFirstChild("HumanoidRootPart").CFrame.Position, Vector3.new(coords of literaly anywhere))
script.Parent.Parent:PivotTo(new_CFrame)
-- This just does nothing, no errors
script.Parent.Parent:PivotTo(player:FindFirstChild("HumanoidRootPart").CFrame)
-- same problems as above
script.Parent.Parent.PrimaryPart.CFrame = player.HumanoidRootPart.CFrame * CFrame.new(0, offset_x, offset_y)
-- this will instantly rotate my character while doing nothing
script.Parent.Parent.PrimaryPart.Position = player.HumanoidRootPart.Position
script.Parent.Parent.PrimaryPart.Orientation = player.HumanoidRootPart.Orientation
-- This works fine moving the primary part, however ONLY the primary part is moved, ignoring all the other things welded to it
However, I DO have a solution in mind, however it is very bodge and I would rather not use it at all if I can help it, and is listed below:
- Use solution 1 above to move crate to HumanoidRootPart
- Use a large amount of trigenometry equations and vector3 calculations to move the crate to the desired n studs in front of the HumanoidRootPart
- Use several Align Orientation constraints with a VERY high responsiveness and torque to keep the crate in position
I don’t want to use this solution, as it is a lot of work to calculate and relies on the incredibly buggy roblox physics system
Please can you help? This has stumped me for hours and I would really appreciate if if you could lend a hand. Please ask more questions about my problem if you found the information above insufficient, as I would be happy to reply to any queries regarding the problem.
Thank you sincerely for reading, JSS64641