Answered by
5 years ago Edited 5 years ago
On line 3, you are attempting to access game.StarterPlayer, this does not find the player, this is what is used to add into the player when they join the game/respawn ("StarterCharacter" is not exactly a thing either). So since this should be a local script, use game.Players.LocalPlayer.Character. LocalPlayer finds the player who uses the GUI, and Character will reference the Player >model< inside the game.Workspace.
You do not require an iterator loop on line 6 (for i, v in pairs(x)) as you are only trying to access one part (HumanoidRootPart), and can be specified with a simple directory.
magnitude is a property of vector values, works as a way of finding the length of a vector, (equates to Pythagoras' Theorem), so for any value classified as a vector, add a ".magnitude" to find it's "length". Of course, we must first subtract the two vectors, because the distance will be based around the origin of the grid they use. (Line 7 of OP's code)
Misc: Typo occurred in line 7 "Positon"; Lines 8 & 10 "Guest.BillboardGui" simplified to "Ggui".
Here is what should be a simplified version of the code..
02 | Ggui = script.Parent.BillboardGui |
03 | local player = game.Player.LocalPlayer.CharacterAdded:wait() |
06 | if (player.HumanoidRootPart.Position - Guest.HumanoidRootPart.Position).magnitude < = 10 then |
07 | Ggui.ImageButton.Visible = true |
09 | Ggui.ImageButton.Visible = false |
EDIT: The player's character does not immediately create, so I have modified the code to account for that (line 3; credit to user alphawolvess).
EDIT2: Localscripts will not run when parented under "Guest" .. this must be placed in game.StarterPlayer.StarterPlayerScripts and specify the NPC from there.. ask me if any more problems arise.