lua - How to find the position of a player in roblox - Stack Overflow

I am making a game in roblox and a part of what I am trying to do is find a player who pressed a keybin

I am making a game in roblox and a part of what I am trying to do is find a player who pressed a keybind localy and find the players position(I only need help with finding the players position not the keybind)

I tried to search online but i didnt find a solution to my problem

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.G then
        _G.MalevolentShire = true
    
            
    end
end)

I am making a game in roblox and a part of what I am trying to do is find a player who pressed a keybind localy and find the players position(I only need help with finding the players position not the keybind)

I tried to search online but i didnt find a solution to my problem

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.G then
        _G.MalevolentShire = true
    
            
    end
end)
Share Improve this question asked Mar 8 at 13:23 user29931871user29931871 11 silver badge
Add a comment  | 

2 Answers 2

Reset to default 1

Every player has an invisible part located by their torso called HumanoidRootPart, that can be used as an inner hitbox or to track the player's position. To access it on a LocalScript, one can use Game.Players.LocalPlayer.Character.HumanoidRootPart then just get the position like on a normal part.

Since this is a LocalScript, you can use game.Players.LocalPlayer.Character.HumanoidRootPart.Position to get the Vector3 of the player's character. If you want to get the CFrame of the player's character, use game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame. Example:

print(game.Players.LocalPlayer.Character.HumanoidRootPart.Position) --> 0, 5, 0 (example value)

-- To get rotation:

print(game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame.Rotation) --> 0, 0, 0 (example value)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744895134a4599649.html

相关推荐

  • lua - How to find the position of a player in roblox - Stack Overflow

    I am making a game in roblox and a part of what I am trying to do is find a player who pressed a keybin

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信