Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i get the character position?

I started scripting a month ago and i want to know how to get the character postion in my case.

script.Parent.MouseButton1Click:Connect(function()
	while true do
		local part = Instance.new("Part", game.Workspace)
		part.Position = Vector3.new(game.Players.LocalPlayer.Character.UpperTorso.Position)
		part:Clone()
		wait(0.0000000001)
	end
end)

I wanted to do a block spam for a lag test but it does not work.

3 answers

First of all, how is putting a part in someone's torso and duplicating it over and over again related to getting their position?

If you want to know where the character is:

game.Players.PlayerAdded:Connect(function(player)
        charPos = player.Character.UpperTorso.Position
        print(charPos)
end)

2 comments

0

Use the HRP.

0

The game doesn't detect "Character" so i still can't get the position.

I recommend using the HumanoidRootPart for the position. It works with both R6 and R15.

You can try this:

local CharacterPosition = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart").Position

Ok, I now realize you probably need to wait for the character to load.

local Player = game.Players.LocalPlayer
repeat wait() until Player.Character -- Should wait for the "Character"
local CharacterPosition = Player.Character:WaitForChild("HumanoidRootPart").Position

1 comment

0

The game doesn't detect "Character" so i still can't get the position.

function GetCharacterPos(Character)
	if Character:FindFirstChild("HumanoidRootPart") then
		local RootPart = Character:FindFirstChild("HumanoidRootPart")
		return(RootPart.Position)
	end
end
-- Anytime you need to get a characters position, just run the fire the function and it will act as a variable giving data.
-- Please feed the character(in workspace)
-- PLEASE CLICK GET SOURCE SO THE SCRIPT IS PROPERLY FORMATED.
print(GetCharacterPos(game.Players.LocalPlayer.Character)) -- This runs the function, then finds the localPlayers postion.

This discussion is preserved as it was. New answers, comments, and votes are closed.