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

How do you find a character's position?

Asked by 9 years ago

I was wondering because each part of the character stays the same position,and I want this script to update when the character moves or the position of the character is changed.

How would I find out a character position?

game.Players.PlayerAdded:connect(function(Player)
    Player.CharacterAdded:connect(function(Character)
        Head = Character:WaitForChild("Head") --In case the head isn't found when you spawn.
        Head.Changed:connect(function(prop) --We call the Changed event on the head part.
            if prop == "Position" then --The check to see if the property that changed is the position property.
                local Ray = Ray.new(Head.Position,
                Head.CFrame.lookVector.unit*1000)
                local Hit = Workspace:FindPartOnRay(Ray)
                if not Hit then
                    print("Nope")
                else
                    print(Hit)
                end
            end
        end)
    end)
end)


1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

Changed events do not fire for certain properties, like Velocity. Because of your problem, I assume that it doesn't fire when Position changes as well. You can fix this with a while loop. For example,

local position = workspace.Part.Position
while true do
    wait()
    if workspace.Part.Position ~= position then
        position = workspace.Part.Position
        print("Position changed")
    end
end

I hope I helped!

Ad

Answer this question