Tweening CFrame not working

Yesterday I was trying to make an earth bending thing for the player because I am doing a 2 hour challenge to sharpen my scripting skills. I am trying to make a wall come out of the ground and go in the direction the player is facing, but it just goes in one direction.

Download:
Earth Bending.rbxl (52.4 KB)

The scripts are in Character Scripts. The script I am having problems in is called “EarthBender” (… lol). The line that I can’t fix is Line 57 - 58.
I’m not that sure if it’s line 57 and 58, it could be just the tweening.

Edit: Where it says goals, I know that I should replace cf with CFrame.

1 Like

It’s late for me right now, so if I don’t answer I will answer any replies in the morning. ~12 hours sorry! :frowning:

Status: Online

I’m trying to just make a wall move forwards from the player… What do you mean by falling? Also, It’s late. I will see the replies tomorrow. Sorry, but thanks :slight_smile:

Well, i had to fix the console errors with type mismatches then i tried editing the wall position and then i just noticed that your “torso” variable is declared at the start of the script… You are then trying to use it’s position but it is giving you the original torso position since you saved it at the start of the script instead of getting the new one in the function. It works for me now but i edited some CFrame values for the position and i dont know which ones xd

He said the scripts are in the player not the parts

1 Like

I’m pretty sure variables don’t work like that. I’m not sure. I’ll try moving it into the event tho.

It works now kind of…??? I’ll show a video. Please give me a minute. :slight_smile:

Yeaah, you are right, my bad :happy3: i got mixed up torso and torso.position… Well, then the problem is with your CFrames and type mismatches

I just changed it right now! :slight_smile:

Changed script:

local TS = game:GetService('TweenService')
local char = script.Parent
local animIsPlaying = false
local damage = {
	EarthWall = 12,
	EarthJump = 15,
	EarthShock = 28
}
local cooldown = {
	EarthWall = 1,
	EarthJump = 2,
	EarthShock = 5
}
local cooldownActive = {
	EarthWall = false,
	EarthJump = false,
	EarthShock = false
}

local hum = char:WaitForChild('Humanoid')
--local torso = char:WaitForChild('Torso')
local ev = char.Bend
local ev2 = char.OnCooldown

ev.OnServerEvent:Connect(function(plr, bend)
	if not animIsPlaying then
		local anim = hum.Animator:LoadAnimation(script[bend])
		local attacks = 0
		local torso = char:WaitForChild('Torso')
		if not cooldownActive[bend] then
			local earth = Instance.new('Part', char)
			local movementPoints = {
				Appear = CFrame.new(),
				Disappear = CFrame.new()
			}
			local appearanceTime = {
				Appear = 0,
				Disappear = 0
			}
			local info = {
				Appear = TweenInfo.new(),
				Disappear = TweenInfo.new()
			}
			local goals = {
				Appear = {},
				Disappear = {}
			}
			local tween = {
				Appear = 'I am dum',
				Disappear = 'Stupid too'
			}
			
			anim.Priority = Enum.AnimationPriority.Action
			anim:Play()
			
			if bend == 'EarthWall' then
				movementPoints.Appear = CFrame.new(torso.CFrame.LookVector * 80)
				movementPoints.Disappear = CFrame.new(torso.CFrame.LookVector * 100)
				appearanceTime.Appear = 0.5
				appearanceTime.Disappear = 0.9
				info.Appear = TweenInfo.new(
					appearanceTime.Appear,
					Enum.EasingStyle.Exponential,
					Enum.EasingDirection.Out,
					0,
					false,
					0
				)
				info.Disappear = TweenInfo.new(
					appearanceTime.Disappear,
					Enum.EasingStyle.Linear,
					Enum.EasingDirection.Out,
					0,
					false,
					0
				)
				goals.Appear = {
					CFrame = movementPoints.Appear
				}
				goals.Dissapear = {
					CFrame = movementPoints.Disappear
				}
				
				earth.Name = bend
				earth.Material = Enum.Material.Slate
				earth.Color = Color3.fromRGB(115, 115, 115)
				earth.Size = Vector3.new(10, 7, 4)
				earth.CanCollide = true
				earth.CFrame = CFrame.new(movementPoints.Appear.X, -4, torso.CFrame.Z)
				earth.Anchored = true
				
				print(movementPoints)
			elseif bend == 'EarthJump' then
				movementPoints.Appear = CFrame.new(torso.CFrame.X, 25, torso.CFrame.Z)
				movementPoints.Disappear = CFrame.new(torso.CFrame.X, -30, torso.CFrame.Z)
				appearanceTime.Appear = 0.75
				appearanceTime.Disappear = 0.8
				info.Appear = TweenInfo.new(
					appearanceTime.Appear,
					Enum.EasingStyle.Linear,
					Enum.EasingDirection.InOut,
					0,
					false,
					0
				)
				info.Disappear = TweenInfo.new(
					appearanceTime.Disappear,
					Enum.EasingStyle.Exponential,
					Enum.EasingDirection.InOut,
					0,
					false,
					0
				)
				goals.Appear = {
					CFrame = movementPoints.Appear
				}
				goals.Disappear = {
					CFrame = movementPoints.Disappear
				}
				
				earth.Name = bend
				earth.Material = Enum.Material.Slate
				earth.Color = Color3.fromRGB(115, 115, 115)
				earth.Size = Vector3.new(15, 50, 15)
				earth.CanCollide = true
				earth.CFrame = movementPoints.Disappear
				earth.Anchored = true
			end

			cooldownActive[bend] = true
			ev2:FireClient(plr, bend, cooldownActive[bend])
			
			hum.WalkSpeed = 0
			animIsPlaying = true
			
			char[bend].Touched:Connect(function(hit)
				local hum2 = hit.Parent:FindFirstChild('Humanoid')

				if hum2 and hum2 ~= hum then
					if attacks < 1 and animIsPlaying then
						attacks += 1

						hum2:TakeDamage(damage[bend])
					end
				end
			end)
			
			wait(0.45)
			
			tween.Appear = TS:Create(earth, info.Appear, goals.Appear)
			tween.Appear:Play()
			
			wait(appearanceTime.Disappear)
			
			tween.Disappear = TS:Create(earth, info.Disappear, goals.Disappear)
			tween.Disappear:Play()
			
			wait(anim.Length - appearanceTime.Disappear)
			
			hum.WalkSpeed = 16
			animIsPlaying = false

			wait(cooldown[bend])

			cooldownActive[bend] = false
			ev2:FireClient(plr, bend, cooldownActive[bend])
		end
	end
end)

It still MOVES in one direction but at least it ends up where it should.

1 Like

I didn’t look at the uh file but i assume what you would do is get the humanoidRootPart.CFrame.LookVector then you continue the effect there! If this doesn’t work lmk i will download the file and look at it myself.

1 Like

I already tried Humanoid Root Part before I changed it to torso. Also, it’s R6.

I believe these are the only changes i did now (puts the wall 80 studs from the player’s torso and facing away from him)

movementPoints.Appear = CFrame.new(torso.Position + torso.CFrame.LookVector * 80,torso.Position + torso.CFrame.LookVector * 81)

and when you create the wall (just places it at the location but 10 studs down)

earth.CFrame = movementPoints.Appear - Vector3.yAxis*10

Also i have no idea for what you use the Disappear variable so you might need to edit that as well accordingly

1 Like

This is great thank you! What do I change to make the wall start from the player? (earth.CFrame = …)

earth.CFrame = CFrame.new(torso.Position + torso.CFrame.LookVector * DISTANCE,torso.Position + torso.CFrame.LookVector * DISTANCE+1)
Just change DISTANCE to whatever amount you want and thats how far it will start from the player

1 Like

Error when that happens: Workspace.SirHoog.EarthBender:92: attempt to perform arithmetic (add) on Vector3 and number

I think the

torso.Position + torso.CFrame.LookVector * distance

is the problem?

Nope, can’t be if distance is just a number then you are adding vector to a vector multiplied by a number which is still a vector. I suggest sharing the whole line

EDIT: this is my fault i guess, should have put it in round brackets… (DISTANCE+1)
didn’t expect that you’d make it into a variable :happy3:

earth.CFrame = CFrame.new(torso.Position + torso.CFrame.LookVector * distance,torso.Position + torso.CFrame.LookVector * (distance+1))

I mean, it moves now! That’s great, but the block just moves 10 studs towards the player…
As in it starts at like 110 and then moves to 100.

distance is 100 :cold_face:

Well, what is your distance value then cuz it works for me fine when i set it to 10 since you wanted it to start at the player’s position

That makes sense… You create the wall 100 studs away from the player and then your appear tween plays which puts it to movementPoints.Appear which is now 80 studs away from the player so it’s going backwards… Your disappear tween never plays for some reason

EDIT: Found out why your disappear tween never plays. You mistyped goals.Disappear = ..

BTW the whole script i have now looks like this:
local TS = game:GetService('TweenService')
local char = script.Parent
local animIsPlaying = false
local damage = {
	EarthWall = 12,
	EarthJump = 15,
	EarthShock = 28
}
local cooldown = {
	EarthWall = 1,
	EarthJump = 2,
	EarthShock = 5
}
local cooldownActive = {
	EarthWall = false,
	EarthJump = false,
	EarthShock = false
}

local hum = char:WaitForChild('Humanoid')
--local torso = char:WaitForChild('Torso')
local ev = char.Bend
local ev2 = char.OnCooldown

ev.OnServerEvent:Connect(function(plr, bend)
	if not animIsPlaying then
		local anim = hum.Animator:LoadAnimation(script[bend])
		local attacks = 0
		local torso = char:WaitForChild('Torso')
		if not cooldownActive[bend] then
			local earth = Instance.new('Part', char)
			local movementPoints = {
				Appear = CFrame.new(),
				Disappear = CFrame.new()
			}
			local appearanceTime = {
				Appear = 0,
				Disappear = 0
			}
			local info = {
				Appear = TweenInfo.new(),
				Disappear = TweenInfo.new()
			}
			local goals = {
				Appear = {},
				Disappear = {}
			}
			local tween = {
				Appear = 'I am dum',
				Disappear = 'Stupid too'
			}

			anim.Priority = Enum.AnimationPriority.Action
			anim:Play()

			if bend == 'EarthWall' then
				local distance = 10
				movementPoints.Appear = CFrame.new(torso.Position + torso.CFrame.LookVector * distance,torso.Position + torso.CFrame.LookVector * (distance+1))
				movementPoints.Disappear = CFrame.new(torso.Position + torso.CFrame.LookVector * 100,torso.Position + torso.CFrame.LookVector * 101)
				appearanceTime.Appear = 0.5
				appearanceTime.Disappear = 0.9
				info.Appear = TweenInfo.new(
					appearanceTime.Appear,
					Enum.EasingStyle.Exponential,
					Enum.EasingDirection.Out,
					0,
					false,
					0
				)
				info.Disappear = TweenInfo.new(
					appearanceTime.Disappear,
					Enum.EasingStyle.Linear,
					Enum.EasingDirection.Out,
					0,
					false,
					0
				)
				goals.Appear = {
					CFrame = movementPoints.Appear
				}
				goals.Disappear = {
					CFrame = movementPoints.Disappear
				}
				
				earth.Name = bend
				earth.Material = Enum.Material.Slate
				earth.Color = Color3.fromRGB(115, 115, 115)
				earth.Size = Vector3.new(10, 7, 4)
				earth.CanCollide = true
				earth.CFrame = CFrame.new(torso.Position + torso.CFrame.LookVector * distance,torso.Position + torso.CFrame.LookVector * (distance+1)) - Vector3.yAxis*10
				earth.Anchored = true

				print(movementPoints)
			elseif bend == 'EarthJump' then
				movementPoints.Appear = CFrame.new(torso.CFrame.X, 25, torso.CFrame.Z)
				movementPoints.Disappear = CFrame.new(torso.CFrame.X, -30, torso.CFrame.Z)
				appearanceTime.Appear = 0.75
				appearanceTime.Disappear = 0.8
				info.Appear = TweenInfo.new(
					appearanceTime.Appear,
					Enum.EasingStyle.Linear,
					Enum.EasingDirection.InOut,
					0,
					false,
					0
				)
				info.Disappear = TweenInfo.new(
					appearanceTime.Disappear,
					Enum.EasingStyle.Exponential,
					Enum.EasingDirection.InOut,
					0,
					false,
					0
				)
				goals.Appear = {
					CFrame = movementPoints.Appear
				}
				goals.Disappear = {
					CFrame = movementPoints.Disappear
				}

				earth.Name = bend
				earth.Material = Enum.Material.Slate
				earth.Color = Color3.fromRGB(115, 115, 115)
				earth.Size = Vector3.new(15, 50, 15)
				earth.CanCollide = true
				earth.CFrame = movementPoints.Disappear
				earth.Anchored = true
			end

			cooldownActive[bend] = true
			ev2:FireClient(plr, bend, cooldownActive[bend])

			hum.WalkSpeed = 0
			animIsPlaying = true

			char[bend].Touched:Connect(function(hit)
				local hum2 = hit.Parent:FindFirstChild('Humanoid')

				if hum2 and hum2 ~= hum then
					if attacks < 1 and animIsPlaying then
						attacks += 1

						hum2:TakeDamage(damage[bend])
					end
				end
			end)

			wait(0.45)

			tween.Appear = TS:Create(earth, info.Appear, goals.Appear)
			tween.Appear:Play()
			
			tween.Appear.Completed:Wait()
			--wait(appearanceTime.Disappear)

			tween.Disappear = TS:Create(earth, info.Disappear, goals.Disappear)
			tween.Disappear:Play()

			wait(anim.Length - appearanceTime.Disappear)

			hum.WalkSpeed = 16
			animIsPlaying = false

			wait(cooldown[bend])

			cooldownActive[bend] = false
			ev2:FireClient(plr, bend, cooldownActive[bend])
		end
	end
end)