Problem with animating a moving part w/ for & CFrame

Been working on a small project and encountered a troublesome bug. Since I’m not a big fan of Welds & WeldConstraints I decided to use them in this particular project for some actions.

I have a model with 4 parts. a base and 3 outlines
c4f630b8506b04d16150ec34a5c327ac

The outlines are welded to the base part and I am trying to make a moving part on-click using the script

local Click = script.Parent.ClickDetector
local PMAIN = script.Parent.Main
local P1 = script.Parent[“1”]
local P2 = script.Parent[“2”]
local P3 = script.Parent[“3”]

local function OnClick(Player)

P1.CanCollide = false
P2.CanCollide = false
P3.CanCollide = false
PMAIN.CanCollide = false

for trnaPM = -191.57,-188.57,0.1 do
script.Parent.Main.CFrame = CFrame.new(PMAIN.Position.X, PMAIN.Position.Y, trnaPM)
wait(0.005)
end

script.Parent.ClickDetector:Destroy()
end

Click.MouseClick:connect(OnClick)

I usually do not use Welds or WeldConstraint at-all so I’m not really sure on how to exactly place them (I just used logic)

The rooting goes like this:
3803376f712633a63d2a960f1a304112

I’d assume the welds are correct since I’ve tested moving the part in various ways and they leached onto the base part.

But when running the script in testing & clicking this happens:
com-video-to-gif

I have tried using Vector3 instead of CFrame but that just detects collision and makes the part go on top of the build.

I have also tried messing with anchors and such but then the part just falls and that beats the point…

Was wondering maybe either my script is a mess or my welding is, would appreciate any help I could get, maybe even a different method to move the part.


If anyone is interested in watching that from up close you can go here : The Reckoning - Roblox

Walk the path, enter the cave, and click the loose part near the windows.

1 Like

does it need to be unanchored if not why you dont use cframe with tweenservice?
Because i dont see a reason why your script shoudent work

They need to be anchored. The point is to keep the part in-place not make it fall down.

I did tried to mess with unachor out of frustration but as I said in the thread:

I have also tried messing with anchors and such but then the part just falls and that beats the point…

I have tried TweenService. Same result basically. I believe my welding is the issue here…

well i would say CFrame the model. no need for welds then.
Model is a Datatable i send to the client to make the tween smooth

local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = Model.Model:GetPrimaryPartCFrame()
CFrameValue:GetPropertyChangedSignal("Value"):connect(function()
	Model.Model:SetPrimaryPartCFrame(CFrameValue.Value)
end)
local tween = TweenService:Create(CFrameValue, TweenInfo.new(Model.Duration,Model.EasingStyle,Model.EasingDirection), {Value = Model.EasingCF})
tween:Play()
tween.Completed:connect(function()
	CFrameValue:Destroy()
end)	

I think I’ve already mentioned this to you before but your method of tweening is going to result in broken pieces when you call SetPrimaryPartCFrame too often due to float point errors.

1 Like

i am using it for my own game. and have no problens, so its probably you getting those error’s

Incorrect. This happens to everyone. There are several topics on the DevForum regarding SetPrimaryPartCFrame ripping apart models after continuous calls.

https://devforum.roblox.com/t/more-efficient-way-to-move-anchored-models-than-setprimarypartcframe/19207

https://devforum.roblox.com/search?q=SetPrimaryPartCFrame

2 Likes

I’ll need to stick to “for” table because I also plan to make the part disappear in the same instance instead of loading the part with more loops. Any other methods you can think of?

As i said i dont have anyproblems with it. and i am only giving @UhmTex some scripting help

you could ad a tween to it with transparency

You don’t understand. It might work but there is an inherent problem in that method. Eventually with enough waiting or usage of that, you will see that your models tear apart when you call it too often. If all your parts are anchored and you’re using SetPrimaryPartCFrame, there will be float point errors affecting your assembly. I’m not saying this for the heck of it, I’m saying this from a factual standpoint. This method may be workable but you shouldn’t rely on it. When you start experiencing issues and player complaints, that’s when things get messy.

Welding all your unanchored parts to an anchored root with Motor6Ds and tweening the assembly doesn’t result in float point errors and you only need to worry about joint breaking items like explosions or Instance::BreakJoints.

2 Likes

I will stick to my current method and try to find a way to make it work via the same actions. If I will not find a suitable fix I will turn my hand to SetPrimaryPartCFrame & Tweening.

So, any other suggestions are appreciated.

i think your getting a bit off topic from the original post.
uhmtex can use tween service just fine to cframe it, there’s absolutely no reason for you to comment that it might glitch out or not.
because as shown in the gif uhmtex is just moving it to the side. and probably not doing anything else.

My posts aren’t going off-topic. The topic is related to model tweening (which is a question that’s been asked several times before) and I’m disagreeing with the method you’re trying to give UhmTex because, as I’ve said countless times, it isn’t reliable in the long run.

What I’m trying to explain to you is that a better method of tweening models without running into issues with models being torn apart is to have your parts unanchored, welded to an assembly with Motor6D and that root gets moved. In practice you want to let your players have the best experience and use a proper method that has a very low fail threshold. I never said anything against the usage of TweenService, I’m against the use of SetPrimaryPartCFrame. I linked you several threads in which people spoke about the function being faulty.

Disagreeing for the sake of it is not fair to me. I’m trying to explain a workable method with limited ability to interrupt player experience while helping solve the problem.

3 Likes

To address the problem directly: if what you aim to do is tween a model (or as you wrote, “animate” it), there are several methods available by searching the DevForum, as well as the brief discussion above. Take for example this tutorial.

As for if you want to add transparency to the model, you’re going to have to simultaneously with the aforementioned tween. You can do this in a for loop.

Typically in the end, for moving a part, you want to aim to use it’s CFrame as opposed to it’s Vector. This especially goes for a model. The trick is to move things as an assembly or relative to a central point, not individually.


Note for when posting code to the DevForum: you should include it in a code block instead of a quote block. You can accomplish that with backticks. It just helps us to read the code you posted better.

```lua
-- Code here
```

print("Hello world")
2 Likes

The comment regarding the code block is much appreciated. Thanks.

I will take a look at the tutorial and give those options a try next time I edit the project.

Again, Much appreciated.

1 Like