Moving a Model Without Separating It

Hi all,

I’m trying to make a capture the flag script and I’m to the point where I move the captured flag onto the back of the player. Here is a snippet of my code:

	local newflag = touchedFlag.Parent:FindFirstChild(flagName):Clone()
	for i, v in pairs(newflag:GetChildren()) do --unanchors new flag and makes it non collidable
		if v:IsA("BasePart") then
			v.CanCollide = false
			v.Anchored = false
		end
	end
	
	newflag.PrimaryPart = newflag:WaitForChild("FlagPole")
	local upperTorso = char:FindFirstChild("UpperTorso")
	newflag.Name = flagColor.."TeamFlag"
	newflag.Parent = char
	newflag.PrimaryPart.Position = upperTorso.Position + Vector3.new(0, 10, 0)

The issue is that when I move the cloned object, it separates the “FlagPole” part from the actual flag. I’ve tried moving the part by itself, which didn’t work, and I tried setting the model’s PrimaryPart and moving that, still to no avail. Here’s a poor visual from the built-in screen capture:

FlagError.wmv (1.5 MB)

I think I did a poor job explaining but I’m so stumped I can’t think.

Haha, of course it didn’t embed the recording! :upside_down_face:

Try Model:SetPrimaryPartCFrame(cf), it should move the whole model

1 Like

I tried that after writing my topic with the line:

newflag:SetPrimaryPartCFrame(upperTorso.CFrame)

This is the result. As you can see, the flag detached from the pole somehow, I’m not sure how. (hopefully my screenshots embed :crossed_fingers:)

Original model:

Model after cloning:

You can see the flag pole went into my torso but the flag itself decided to run away. (No, the flag is not laying on the ground, it is still welded to the pole so it shakes and moves with my character, it’s just offset in a weird way)

What kind of welds are you using?

Just a regular “Weld” instance, the same one that inserts automatically when you insert a part into workspace and it collides with the baseplate

Do you really need to set the position of the flag? You could just make a new weld and then weld the cloned flag to the torso

But how would I get the flag to stick to the back of the torso? Or at least move along with the player? If I welded the model to the torso without moving it, to my understanding, it would create a very weird effect where the flag is floating around next to the player in a weird way

If you just weld the flag to the torso, it will stick to it properly. Just edit the C0 of the weld so the flag isn’t inside the torso.

local weld = Instance.new("Weld", newflag.PrimaryPart)
weld.Part0 = upperTorso
weld.Part1 = newflag.PrimaryPart
weld.C0 = CFrame.new(0, 0, 2)

I still can’t figure out what’s separating the flag from the pole like that. I tried to get off of the ground for a better angle

Any chance you could send me the place file here or in pm?

I don’t think I can sorry :sweat_smile: my friend owns the place. Do you have any ideas of what could possibly be an issue within the place?

Could you send a visual of how the flag is supposed to look on the avatar?

Similar to this except I haven’t done any positioning or angling because the flag offsets from the pole for some reason when a clone is created. I’ve checked my functions in both my module and my regular script, I never alter the flag(red part) directly.

Thanks for that. I’ll try reproducing the issue and report back if anything comes up.

Think I found a fix, you’re going to have to play around with CFrames though.

Instead of using welds, try weld constraints as they’re newer and more optimized in my experience.

Make the flag’s PrimaryPart the pole.

local primaryPart = workspace.Model.PrimaryPart -- the pole.
local torso = workspace['7z99'].Torso -- I used my torso as an example.
workspace.Model:SetPrimaryPartCFrame(torso.CFrame * CFrame.new(0, 0, 1) --[[offset it 1 stud behind the user's torso]] * CFrame.Angles(math.rad(0), 0, math.rad(-45) --[[rotation]])) 
local weld = Instance.new('WeldConstraint') -- Create a new weldconstraint between the user's torso and the flagpole's PrimaryPart
weld.Parent = torso 
weld.Part0 = primaryPart 
weld.Part1 = torso

You’re going to have to play around with the pole’s rotation. I also recommend turning off the flag’s collision and set its massless property to true, this is just my opinion though.

After a bit of playing around:

Final script:

local primaryPart = workspace.Model.PrimaryPart
local torso = workspace['7z99'].Torso 
workspace.Model:SetPrimaryPartCFrame(torso.CFrame * CFrame.new(0, 0, 1) * CFrame.Angles(, 0, math.rad(-62.5))) 
local weld = Instance.new('WeldConstraint') 
weld.Parent = torso 
weld.Part0 = primaryPart 
weld.Part1 = torso 
for i,v in pairs(workspace.Model:GetChildren()) do 
    if v:IsA('BasePart') then 
        v.Anchored = false 
        v.CanCollide = false 
    end 
end

Also made this model file for you:
flag.rbxm (6.1 KB)

Hey so I got it working and here was my solution:

There was a regular “Weld” between the original model’s pole and flag. Somehow, by some strange chance I guess, the weld was breaking after being cloned(what???). After changing the weld in the model to a weld constraint(as well as the weld in the script), it works perfectly. Not sure whats happening, but this is very helpful info.

PSA: Stop using old welds! They don’t work! :laughing:

1 Like