To not cause an error, we need to listen for the event (in this case plr.CharacterAdded:Connect (function (character).) that triggers when the player’s character gets. Local Direction: Vector3 = Head. If that doesn’t work, you may need to use plr.CharacterAdded:Connect (function (character) This might because the player’s character hasn’t loaded in yet. ![]() You can find it like this: local plr local chr plr.Character. To detect the addition of Player objects, it is recommended to use the Players.PlayerAdded event (instead of Instance.ChildAdded on the Players service). So based on the above, you can do this: local Head: BasePart = 1Click:Connect (function (player) Local char player:WaitForChild ('character') Local humanoid chat.humanoid Humanoid.Health humanoid.Health - 50 End) This script will halfen and then on second click kill the player. You can get a table of current Player objects using Players:GetPlayers () again, use this instead of Instance:GetChildren (). So if we want to find the position the character is looking at, we need to multiply this LookVector by a number which will denote the number of studs in the direction of the character we want to look and then add it with the position of the Head. But there is a slight issue, you see- LookVector is not a positional vector but rather a directional vector, as such it will have a Magnitude (length) of 1. function GetCharacter (UserName) local UserId players:GetUserIdFromNameAsync (UserName) local player players:GetPlayerByUserId (UserId) local character player.Character or player. And voila you got the direction where the character is facing. To do this, we can reference the character Head and then get the LookVector property of its CFrame. ( since we can't get the CFrame of a model). ![]() Now if you wanna find the where the character is looking, we could check the direction the character's Head is facing by utilizing its CFrame. Now if you wanna find the where the character is looking, we could check the direction the characters Head is facing by utilizing its CFrame.(since we cant get the CFrame of a model). So in ROBLOX, all BaseParts have a property named CFrame which represents the Position and Orientation of that BasePart. function GetCharacter (UserName) local UserId players:GetUserIdFromNameAsync (UserName) local player players:GetPlayerByUserId (UserId) local character player.Character or player.CharacterAdded:Wait print (UserId) print (player) print (character) return character end local Char GetCharacter (Player.Name) if Char then print ('. So in ROBLOX, all BaseParts have a property named CFrame which represents the Position and Orientation of that BasePart.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |