Problem with TweenService and CFrame

Hello, I created an effect with CFrame and TweenService, and he has a problem that I don’t know how I can solve, what happens is this, when I walk the effect is left behind, it is as if it was generated behind me, when I stand still the effect is generated in front of me, which is correct. I want the effect to be in front of me whenever I move, but I don’t know what to use to do this, so I’m asking for help. I already looked for tutorials, forums, etc. But I didn’t find anything related to this problem.

Script

game.ReplicatedStorage.BarrageEffectArms.OnServerEvent:Connect(function(player, hum)
	
	local TweenService = game:GetService("TweenService")
	
	local chr = hum.Parent
	local plr = game.Players:GetPlayerFromCharacter(chr)
	local char = player.Character
	
	local Stand = char.Stand
	local StandHRP = Stand:WaitForChild("StandHumanoidRootPart")
	
	local pivotCFrame = StandHRP.CFrame * CFrame.new(0,.5,-8)
	
	local LeftArm = Stand:WaitForChild("Stand Left Arm"):Clone()
	LeftArm:ClearAllChildren()
	LeftArm.CanCollide = false
	LeftArm.Anchored = true
	LeftArm.Parent = game.Workspace.OkStopNoEffects
	game.Debris:AddItem(LeftArm, .40)
	
	
	local RightArm = Stand:WaitForChild("Stand Right Arm"):Clone()
	RightArm:ClearAllChildren()
	RightArm.CanCollide = false
	RightArm.Anchored = true
	RightArm.Parent = game.Workspace.OkStopNoEffects
	game.Debris:AddItem(RightArm, .40)
	
	LeftArm.CFrame = CFrame.new((StandHRP.CFrame * CFrame.new(math.random(-2,-1.5),math.random(-2,2),-4)) .p, pivotCFrame.p) * CFrame.Angles(math.rad(90),0,0)
	RightArm.CFrame = CFrame.new((StandHRP.CFrame * CFrame.new(math.random(1.5, 2),math.random(-2,2),-4)) .p, pivotCFrame.p) * CFrame.Angles(math.rad(90),0,0)
	
	local tween1 = TweenService:Create(LeftArm,TweenInfo.new(.40), {Transparency = 1, CFrame = LeftArm.CFrame * CFrame.new(0, -3,0)}):Play()
	local tween2 = TweenService:Create(RightArm,TweenInfo.new(.40), {Transparency = 1, CFrame = RightArm.CFrame * CFrame.new(0, -3,0)}):Play()

end)

Stopped (the effect is generated in the correct position)

Barrage1Parado

Walking (the effect is generated behind me, the position is wrong. I want him to be in the same position when i’m standing.)

Barrage1

I tried to do an effect like this

I didn’t shoot a video, because it crashes a lot.

The simplest fix is probably to weld (with Weld or Motor6d) the cloned arms to the HumanoidRootPart and modify the weld’s C0 rather than the part’s CFrame.

1 Like

Hi there fellow developer!

Interesting project you have coming along here.

From what I can tell it is an issue with physics. When we consider physics, an object in motion tends to stay in motion. However, a character clone spawned in is not. I would recommend not originating the cloned character from the center of your own character model, but instead try offsetting it and account for that physics. :wink:

1 Like

Okay, I’ll try this, thanks so much for your help! :slight_smile:

Okay, I’ll try this, thanks so much for your help! =)

I made the Weld script, but when the script is executed, I start flying.

BarrageError

Script


game.ReplicatedStorage.BarrageEffectArms.OnServerEvent:Connect(function(player, hum)
	
	local TweenService = game:GetService("TweenService")
	
	local chr = hum.Parent
	local plr = game.Players:GetPlayerFromCharacter(chr)
	local char = player.Character
	
	local Stand = char.Stand
	local StandHRP = Stand:WaitForChild("StandHumanoidRootPart")
	
	local pivotCFrame = StandHRP.CFrame * CFrame.new(0,.5,-8)
	
	local LeftArm = Stand:WaitForChild("Stand Left Arm"):Clone()
	LeftArm:ClearAllChildren()
	LeftArm.CanCollide = false
	LeftArm.Anchored = true
	LeftArm.Parent = game.Workspace.OkStopNoEffects
	local weld = Instance.new("ManualWeld")
	weld.Part0 = LeftArm
	weld.Part1 = StandHRP
	weld.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
	weld.Parent = weld.Part0
	game.Debris:AddItem(LeftArm, .40)
	
	
	local RightArm = Stand:WaitForChild("Stand Right Arm"):Clone()
	RightArm:ClearAllChildren()
	RightArm.CanCollide = false
	RightArm.Anchored = true
	RightArm.Parent = game.Workspace.OkStopNoEffects
	local weld = Instance.new("ManualWeld")
	weld.Part0 = RightArm
	weld.Part1 = StandHRP
	weld.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
	weld.Parent = weld.Part0
	game.Debris:AddItem(RightArm, .40)
	
	LeftArm.CFrame = CFrame.new((StandHRP.CFrame * CFrame.new(math.random(-2,-1.5),math.random(-2,2),-4)) .p, pivotCFrame.p) * CFrame.Angles(math.rad(90),0,0)
	RightArm.CFrame = CFrame.new((StandHRP.CFrame * CFrame.new(math.random(1.5, 2),math.random(-2,2),-4)) .p, pivotCFrame.p) * CFrame.Angles(math.rad(90),0,0)
	
	local tween1 = TweenService:Create(LeftArm,TweenInfo.new(.40), {Transparency = 1, CFrame = LeftArm.CFrame * CFrame.new(0, -3,0)}):Play()
	local tween2 = TweenService:Create(RightArm,TweenInfo.new(.40), {Transparency = 1, CFrame = RightArm.CFrame * CFrame.new(0, -3,0)}):Play()

end)

Don’t anchor the clones!

I this did it here, but it doesn’t work yet, it still has the same problem…


game.ReplicatedStorage.BarrageEffectArms.OnServerEvent:Connect(function(player, hum)
	
	local TweenService = game:GetService("TweenService")
	
	local chr = hum.Parent
	local plr = game.Players:GetPlayerFromCharacter(chr)
	local char = player.Character
	
	local Stand = char.Stand
	local StandHRP = Stand:WaitForChild("StandHumanoidRootPart")
	
	local pivotCFrame = StandHRP.CFrame * CFrame.new(0,.5,-8)
	
	local LeftArm = Stand:WaitForChild("Stand Left Arm"):Clone()
	LeftArm.Name = "BarrageLArm"
	LeftArm:ClearAllChildren()
	LeftArm.CanCollide = false
	LeftArm.Anchored = false
	LeftArm.Massless = true
	LeftArm.Parent = Stand
	local weld = Instance.new("ManualWeld")
	weld.Part0 = LeftArm
	weld.Part1 = StandHRP
	weld.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
	weld.Parent = weld.Part0
	game.Debris:AddItem(LeftArm, .40)
	
	
	local RightArm = Stand:WaitForChild("Stand Right Arm"):Clone()
	RightArm:ClearAllChildren()
	RightArm.Name = "BarrageRArm"
	RightArm.CanCollide = false
	RightArm.Anchored = false
	RightArm.Massless = true
	RightArm.Parent = Stand
	local weld = Instance.new("ManualWeld")
	weld.Part0 = RightArm
	weld.Part1 = StandHRP
	weld.C0 = weld.Part0.CFrame:ToObjectSpace(weld.Part1.CFrame)
	weld.Parent = weld.Part0
	game.Debris:AddItem(RightArm, .40)
	
	LeftArm.CFrame = CFrame.new((StandHRP.CFrame * CFrame.new(math.random(-2,-1.5),math.random(-2,2),-4)) .p, pivotCFrame.p) * CFrame.Angles(math.rad(90),0,0)
	RightArm.CFrame = CFrame.new((StandHRP.CFrame * CFrame.new(math.random(1.5, 2),math.random(-2,2),-4)) .p, pivotCFrame.p) * CFrame.Angles(math.rad(90),0,0)
	
	local tween1 = TweenService:Create(LeftArm,TweenInfo.new(.40), {Transparency = 1, CFrame = LeftArm.CFrame * CFrame.new(0, -3,0)}):Play()
	local tween2 = TweenService:Create(RightArm,TweenInfo.new(.40), {Transparency = 1, CFrame = RightArm.CFrame * CFrame.new(0, -3,0)}):Play()

end)

I removed the

RightArm.Name = "BarrageRArm" and LeftArm.Name = "BarrageLArm"

and it still doesn’t work