Dummy starts sliding or flying off after tweening back to it's original position

I made this script where the unit flies toward the target and punches them and then return back to their original position after the attack. But then this happens… They start sliding out of the place holder. I would like to know the reason on why this happenss… Thank youuu…

Here is the script, I use tween service

function UnitSpawnModule.Attack(newUnit, player)
	local Config = newUnit:WaitForChild("Config")
	local target = UnitSpawnModule.FindTarget(newUnit, Config.Range.Value, Config.TargetMode.Value)
	
	
	if target and  target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then   				
			
if newUnit.Config.TowerName.Value == "Mordecus" then
			local targetcframe = CFrame.lookAt(newUnit.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
			newUnit.HumanoidRootPart.BodyGyro.CFrame = targetcframe
			
			local MobsHit = {}
			
			local TargetPlaceHolder = Instance.new("Part")
			
			local humanoidRootPart = target.HumanoidRootPart
			
			
		
			
			
			if  humanoidRootPart and target.Humanoid then
				if not humanoidRootPart and not target.Humanoid then
					return 
				end
				
				
				TargetPlaceHolder.Size = target.HumanoidRootPart.Size
				TargetPlaceHolder.Position = target.Head.Position
				TargetPlaceHolder.Name = "Target"
				TargetPlaceHolder.Parent = workspace.Misc
				TargetPlaceHolder.Anchored = true
				TargetPlaceHolder.CanCollide = false
				TargetPlaceHolder.CanQuery = false
				TargetPlaceHolder.Transparency = 0

				wait(.3)



				AnimateUnitEvent:FireAllClients(newUnit, "Attack1", target)
				newUnit.Head.Punch:Play()


				TweenService:Create(newUnit.PrimaryPart, TweenInfo.new(0.6),{Position = TargetPlaceHolder.Position}):Play()
				local DamagePart = Instance.new("Part")
				DamagePart.Size = Vector3.new(4.5,1,4.5)
				DamagePart.Transparency = 1
				DamagePart.Color = Color3.new(1, 0.329412, 0.329412)
				DamagePart.Position = TargetPlaceHolder.Position
				DamagePart.Name = "Target"
				DamagePart.Parent = workspace.Misc
				DamagePart.Anchored = true
				DamagePart.CanCollide = false
				DamagePart.CanQuery = false

				local debounce = false

				DamagePart.Touched:Connect(function(hit)
					if hit.Parent.Parent == workspace.Mobs then

						if table.find(MobsHit, hit.Parent) then
							return
						end

						hit.Parent.Humanoid:TakeDamage(Config.Damage.Value)	
						player.leaderstats["Total Damage"].Value += Config.Damage.Value

						table.insert(MobsHit, hit.Parent)
						delay(1, function()
							local index = table.find(MobsHit, hit.Parent)
							table.remove(MobsHit,index)
						end)
						DamagePart:Destroy()

					end


				end)
				

				if target.Humanoid.Health <= 0 then
					player.Money.Value += target.Money.Value
					player.Kills.Value +=1	

				end
			end
			
	
			wait(1.6)
			
			
			TweenService:Create(newUnit.PrimaryPart, TweenInfo.new(.15),{Position = newUnit.PlaceHolder.Position}):Play()
			
			task.wait(Config.Cooldown.Value)
			TargetPlaceHolder:Destroy()

		end
			

	end
	task.wait(.1)
	if newUnit and newUnit.Parent then
		UnitSpawnModule.Attack(newUnit, player)
	end
	
end
1 Like

store the original cframe of the unit before it moves

function UnitSpawnModule.Attack(newUnit, player)
	local Config = newUnit:WaitForChild("Config")
	local target = UnitSpawnModule.FindTarget(newUnit, Config.Range.Value, Config.TargetMode.Value)
	
	if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then   				
		if newUnit.Config.TowerName.Value == "Mordecus" then
			local originalCFrame = newUnit.HumanoidRootPart.CFrame
			local targetcframe = CFrame.lookAt(newUnit.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
			newUnit.HumanoidRootPart.BodyGyro.CFrame = targetcframe
			
			local MobsHit = {}
			
			local TargetPlaceHolder = Instance.new("Part")
			
			local humanoidRootPart = target.HumanoidRootPart
			
			if humanoidRootPart and target.Humanoid then
				if not humanoidRootPart and not target.Humanoid then
					return 
				end
				
				TargetPlaceHolder.Size = target.HumanoidRootPart.Size
				TargetPlaceHolder.CFrame = target.Head.CFrame
				TargetPlaceHolder.Name = "Target"
				TargetPlaceHolder.Parent = workspace.Misc
				TargetPlaceHolder.Anchored = true
				TargetPlaceHolder.CanCollide = false
				TargetPlaceHolder.CanQuery = false
				TargetPlaceHolder.Transparency = 0

				wait(.3)

				AnimateUnitEvent:FireAllClients(newUnit, "Attack1", target)
				newUnit.Head.Punch:Play()

				TweenService:Create(newUnit.PrimaryPart, TweenInfo.new(0.6), {CFrame = TargetPlaceHolder.CFrame}):Play()
				local DamagePart = Instance.new("Part")
				DamagePart.Size = Vector3.new(4.5,1,4.5)
				DamagePart.Transparency = 1
				DamagePart.Color = Color3.new(1, 0.329412, 0.329412)
				DamagePart.CFrame = TargetPlaceHolder.CFrame
				DamagePart.Name = "Target"
				DamagePart.Parent = workspace.Misc
				DamagePart.Anchored = true
				DamagePart.CanCollide = false
				DamagePart.CanQuery = false

				local debounce = false

				DamagePart.Touched:Connect(function(hit)
					if hit.Parent.Parent == workspace.Mobs then
						if table.find(MobsHit, hit.Parent) then
							return
						end

						hit.Parent.Humanoid:TakeDamage(Config.Damage.Value)	
						player.leaderstats["Total Damage"].Value += Config.Damage.Value

						table.insert(MobsHit, hit.Parent)
						delay(1, function()
							local index = table.find(MobsHit, hit.Parent)
							table.remove(MobsHit,index)
						end)
						DamagePart:Destroy()
					end
				end)
				
				if target.Humanoid.Health <= 0 then
					player.Money.Value += target.Money.Value
					player.Kills.Value +=1	
				end
			end
			
			wait(1.6)
			
			TweenService:Create(newUnit.PrimaryPart, TweenInfo.new(.15), {CFrame = originalCFrame}):Play()
			
			task.wait(Config.Cooldown.Value)
			TargetPlaceHolder:Destroy()
		end
	end
	task.wait(.1)
	if newUnit and newUnit.Parent then
		UnitSpawnModule.Attack(newUnit, player)
	end
end
1 Like

Okayy I’ll try that and see if it worksssss

Uhm Nopee still doesn’t work Im afraidd…

alright

function UnitSpawnModule.Attack(newUnit, player)
	local Config = newUnit:WaitForChild("Config")
	local target = UnitSpawnModule.FindTarget(newUnit, Config.Range.Value, Config.TargetMode.Value)
	
	if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then   				
		if newUnit.Config.TowerName.Value == "Mordecus" then
			local placeHolderCFrame = newUnit.PlaceHolder.CFrame
			local targetcframe = CFrame.lookAt(newUnit.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
			newUnit.HumanoidRootPart.BodyGyro.CFrame = targetcframe
			
			local MobsHit = {}
			
			local TargetPlaceHolder = Instance.new("Part")
			
			local humanoidRootPart = target.HumanoidRootPart
			
			if humanoidRootPart and target.Humanoid then
				if not humanoidRootPart and not target.Humanoid then
					return 
				end
				
				TargetPlaceHolder.Size = target.HumanoidRootPart.Size
				TargetPlaceHolder.CFrame = target.Head.CFrame
				TargetPlaceHolder.Name = "Target"
				TargetPlaceHolder.Parent = workspace.Misc
				TargetPlaceHolder.Anchored = true
				TargetPlaceHolder.CanCollide = false
				TargetPlaceHolder.CanQuery = false
				TargetPlaceHolder.Transparency = 0

				wait(.3)

				AnimateUnitEvent:FireAllClients(newUnit, "Attack1", target)
				newUnit.Head.Punch:Play()

				TweenService:Create(newUnit.PrimaryPart, TweenInfo.new(0.6), {CFrame = TargetPlaceHolder.CFrame}):Play()
				local DamagePart = Instance.new("Part")
				DamagePart.Size = Vector3.new(4.5,1,4.5)
				DamagePart.Transparency = 1
				DamagePart.Color = Color3.new(1, 0.329412, 0.329412)
				DamagePart.CFrame = TargetPlaceHolder.CFrame
				DamagePart.Name = "Target"
				DamagePart.Parent = workspace.Misc
				DamagePart.Anchored = true
				DamagePart.CanCollide = false
				DamagePart.CanQuery = false

				local debounce = false

				DamagePart.Touched:Connect(function(hit)
					if hit.Parent.Parent == workspace.Mobs then
						if table.find(MobsHit, hit.Parent) then
							return
						end

						hit.Parent.Humanoid:TakeDamage(Config.Damage.Value)	
						player.leaderstats["Total Damage"].Value += Config.Damage.Value

						table.insert(MobsHit, hit.Parent)
						delay(1, function()
							local index = table.find(MobsHit, hit.Parent)
							table.remove(MobsHit,index)
						end)
						DamagePart:Destroy()
					end
				end)
				
				if target.Humanoid.Health <= 0 then
					player.Money.Value += target.Money.Value
					player.Kills.Value +=1	
				end
			end
			
			wait(1.6)
			
			local returnTween = TweenService:Create(newUnit.PrimaryPart, TweenInfo.new(.15), {CFrame = placeHolderCFrame})
			returnTween:Play()
			returnTween.Completed:Wait()
			
			newUnit.HumanoidRootPart.Anchored = true
			newUnit.HumanoidRootPart.CFrame = placeHolderCFrame
			task.wait()
			newUnit.HumanoidRootPart.Anchored = false
			
			task.wait(Config.Cooldown.Value)
			TargetPlaceHolder:Destroy()
		end
	end
	task.wait(.1)
	if newUnit and newUnit.Parent then
		UnitSpawnModule.Attack(newUnit, player)
	end
end

I’m pretty sure this has more to do with the rig than the code. Was it custom made in blender or is it just parts? Edit: Couldn’t you just anchor the Root?

2 Likes

The rig is made in blender and is supposed to be r6, I just deleted the legs and created the Feet parts in blender. Then added 3 joints for the ankles, knees and the upper leg… Should I use a normal rig??

I’m assuming you had to scale it down. Go to the model and press the arrow next to scale

image

Yes that, it makes Roblox recognize the scale properly and fixes the sliding hopefully

It didn’t it just made the animations look weird but it still slides. Maybe I’ll try to make a normal rig and see if it stops

1 Like