How can I find the Torso in my script?

Greetings developers! I am messing around with CFrames to try and learn how to use them and I want my part, CubeDude to follow the player around. To do this I need to get the Torso’s position, but when I do local char = game.Players.LocalPlayer.Character. Torso isnt one of the children. How come? Here is my full code:

local char = game.Players.LocalPlayer.Character.

local CubeDude = script.Parent
local GreenyBeany = game.Workspace.GreenyBeany

CubeDude.CFrame = CFrame.new(char.po)  --This was me trying to get the Char's position. But now I know I am looking for the Torse position.

Not much but I am just messing around at the moment.

2 Likes

It is because character isn’t loaded. Use it instead:

local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

local CubeDude = script.Parent
local GreenyBeany = game.Workspace.GreenyBeany

CubeDude.CFrame = CFrame.new(char.po)  --This was me trying to get the Char's position. But now I know I am looking for the Torse position.
1 Like

You can learn about lerping CFrames, It is pretty simple.

1 Like

What do you mean by it wasnt loaded? Like it wasnt in the game yet?

1 Like

You don’t really need to get the character’s torso position. You need their rootpart.
Down below, I have provided you with a LocalScript, (thats meant to be put in StarterCharacterScripts).

This will make your “Cubedude” follow you.
Put your “Cubedude” inside of replicated storage for this to work.

local runservice = game:GetService("RunService")

local cubedude = game:GetService("ReplicatedStorage").CubeDude
local cubeclone = cubedude:Clone()

local speed = 0.3

local char = script.Parent
local humanoidrootpart = char:WaitForChild("HumanoidRootPart")

cubeclone.Parent = workspace
cubeclone.CFrame = humanoidrootpart.CFrame

runservice.Heartbeat:Connect(function()
	cubeclone.CFrame = cubeclone.CFrame:Lerp(humanoidrootpart.CFrame * CFrame.new(-5,3,5), speed)
end)

Here are some arcticles that you can learn from if needed!

The greater the speed, the faster the pet moves. The lesser the speed, the slower the pet moves.

1 Like

Thanks! This really helps so much! Now CubeDude can finally go and talk to GreenyBeany. (He is shy)

1 Like

Yes.

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