Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i get the character position?

Asked by 4 years ago

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

Log in to vote
0
Answered by
Zottic 19
4 years ago

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)
0
Use the HRP. Ziffixture 6913 — 4y
0
The game doesn't detect "Character" so i still can't get the position. Applefounde_Davide 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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
0
The game doesn't detect "Character" so i still can't get the position. Applefounde_Davide 0 — 4y
Log in to vote
0
Answered by 4 years ago
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.

Answer this question