Issue finding the HumanoidRootPart while using TweenService

Hey there!

I’m trying to make a tween that shrinks the HumanoidRootPart (I have a custom character which is pretty much just the HumanoidRootPart so the rootpart handles all collisions). For whatever reason, the script returns “TweenService:Create failed because Instance is null” - this instance being the HumanoidRootPart.

Here’s the script (only what I think is relevant to this, all the stuff later and in between these lines of code is probably irrelevant):

local player = game:GetService("Players").LocalPlayer

player.CharacterAdded:Connect(function(newCharacter)

	character = newCharacter

	humanoidRootPart = character:WaitForChild("HumanoidRootPart")
	humanoid = character:WaitForChild("Humanoid")
end)


local crouch = TweenService:Create(humanoidRootPart, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.In, 0, false, 0), {CFrame = CFrame.new(2.5, 3.6, 1)})

I’m unsure what the issue here is, this all seems correct to me but I probably have missed something. Defining the HumanoidRootPart this way seems to work in other parts of the script too.

maybe :sweat_smile:

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

--no need this code, only if we want to listen for other player join the game because this is localscript
--[[
player.CharacterAdded:Connect(function(newCharacter)

	character = newCharacter

	humanoidRootPart = character:WaitForChild("HumanoidRootPart")
	humanoid = character:WaitForChild("Humanoid")
end)
--]]

local crouch = TweenService:Create(humanoidRootPart, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.In, 0, false, 0), {CFrame = CFrame.new(2.5, 3.6, 1)})

That’s it, thanks!
I knew it would be something extremely obvious, just didn’t know what it would be.

1 Like