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:
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)
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
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.
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.
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)
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.