Uhhh... something wrong with tweening the HumanoidRootPart?

hey!

okay so, i got a little problem on my hands when it comes to tweening the humanoidrootpart.
you see, im trying to tween the rootpart so it could go down the black hole, (you’ll see in the video), and instead of going into the black hole, the rootpart decides to tween all the way back to the spawn.

this is so weird man…
look:

here is the code for tweening the rootpart too:

local plr = game:GetService('Players').LocalPlayer
local chr = plr.Character or plr.CharacterAdded:Wait()

local ts = game:GetService('TweenService')
local musichandle = require(plr.PlayerScripts.Player.Music)

local hrp = chr:WaitForChild('HumanoidRootPart')
local hum = chr:WaitForChild('Humanoid')

local downward = ts:Create(hrp, TweenInfo.new(2), {CFrame = hrp.CFrame * CFrame.new(0,-3,0)})

local swordareas = {
	Area1 = 'SwordArea1'
}

hum.Touched:Connect(function(obj)
	if (obj:IsA('Part') and obj.Name == swordareas.Area1) then
		local tpenabled = obj:WaitForChild('TPEnabled')
		obj.Plate.CanCollide = false
		if tpenabled.Value ~= false then
			tpenabled.Value = false
			hrp.CFrame = CFrame.new(hrp.CFrame.Position) * CFrame.Angles(0, 0, 0)
			hrp.Anchored = true
			musichandle:StopMusic()
			downward:Play()
		end
	end
end)

how could i solve this issue? is it something im doing wrong, or maybe it could be another script? please let me know, thank you.
if you need any other materials on how to solve this issue, please let me know too.

1 Like

you’re only creating the downward tween at the top, and its goal {CFrame = hrp.CFrame * CFrame.new(0,-3,0)} is only calculated at the time of initialization (uses whatever the RootPart’s CFrame is whenever the variable is created)

you can fix this by creating it only whenever you need to tween them

local plr = game:GetService('Players').LocalPlayer
local chr = plr.Character or plr.CharacterAdded:Wait()

local ts = game:GetService('TweenService')
local musichandle = require(plr.PlayerScripts.Player.Music)

local hrp = chr:WaitForChild('HumanoidRootPart')
local hum = chr:WaitForChild('Humanoid')

local swordareas = {
	Area1 = 'SwordArea1'
}

hum.Touched:Connect(function(obj)
	if (obj:IsA('Part') and obj.Name == swordareas.Area1) then
		local tpenabled = obj:WaitForChild('TPEnabled')
		obj.Plate.CanCollide = false
		if tpenabled.Value ~= false then
			tpenabled.Value = false
			hrp.CFrame = CFrame.new(hrp.Position)
			hrp.Anchored = true
			musichandle:StopMusic()

			local downward = ts:Create(hrp, TweenInfo.new(2), {CFrame = hrp.CFrame * CFrame.new(0,-3,0)}) -- moved this line

			downward:Play()
		end
	end
end)
2 Likes

This is because you initialized downward when the HumanoidRootPart was still at the spawn. To fix this, initialize downward when you want to tween it.

2 Likes

ohhh okay, thank you for showing me this. I just got back to programming, so im a bit washed when it comes to coding rn :sob:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.