Help with vector3

How would i define the characters torso?

local hit = game.Workspace.TheSpecialNone

game.ReplicatedStorage.TPS:Clone().Parent = workspace

game.Workspace.TPS.CFrame= CFrame.new(hit)
4 Likes

To get the character’s torso, you’ll first need to get the character.

Assuming you have the character, you can use :FindFirstChild or :WaitForChild

local character --The character
local torso = character:FindFirstChild("Torso") or character:FindFirstChild("UpperTorso")

The reason there is an or is because the torso has different names depending on if the character is R6 or R15.
If you’re running this code from the client (aka LocalScript), you should probably use WaitForChild.


Back to getting the character. If you want to run code on all the characters when they spawn in, use this code:

local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        --Code using character here:
        --Ex: local torso = character:WaitForChild("Torso", 5) if not torso then print("No torso found! Maybe ths is R15?") return end
    end)
end)

The first function runs when ever a player is added. Using the player.CharacterAdded event, the next function runs when ever that player gets a new character.


You also might want to consider using the character’s “HumanoidRootPart”. This is a part that hovers in the center of the character and is used as the base for controlling the character. It’s not affected by animations and stuff, so it’s often used more than the torso.


Edit:

local hit = game.Workspace.TheSpecialNone

game.ReplicatedStorage.TPS:Clone().Parent = workspace

game.Workspace.TPS.CFrame= CFrame.new(hit)

If you want to set the CFrame of “TPS” to the CFrame of your player’s torso, you can do this:

local character = game.Workspace.TheSpecialNone

game.ReplicatedStorage.TPS:Clone().Parent = workspace

game.Workspace.TPS.CFrame= CFrame.new(hit)

First I changed the name of your car from hit to character (hit is often used for parts that collide with another part). Then, we need to get the torso. In this case, I would use the HumanoidRootPart, since you want the center/position of the character.

local character = game.Workspace.TheSpecialNone
local torso = character.HumanoidRootPart

game.ReplicatedStorage.TPS:Clone().Parent = workspace

game.Workspace.TPS.CFrame= CFrame.new(hit)

Technically you should probably check first if the character has a HumanoidRootPart, though since you directly look up the character by your username, I assumed it’s fine.

1 Like

i want character to be everyone though.

1 Like
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local humanoidRootPart = character:WaitForChild("HumanoidRootPart", 5)
        if humanoidRootPart then
            local newTPS = game.ReplicatedStorage.TPS:Clone()
            newTPS.CFrame = humanoidRootPart.CFrame
        end
    end)
end)

You can read about events here:

Basically, and event represents something that can happen, and has some functions that allow you to choose what you want to happen when the event happens (often called “handling” the event).

In this case, when a player is added (Player.PlayerAdded) we choose to connect another event for when the newly added player gets a new character (Player.CharacterAdded) and we choose what to do when that new player gets a new character (in this case we create a new TPS and center it at the character’s HumanoidRootPart).

local players = game:GetService("Players")

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local torso = character:WaitForChild("Torso")
		--do stuff with torso
	end)
end)