So I made a script that's supposed to tell the player in which they neighborhood they are after they exit the current one (basically like the city names that appear in gta games) but it doesn't work:
01 | game.Players.LocalPlayer.CharacterAdded:Wait() |
02 | local player = game.Players.LocalPlayer |
03 | local char = game.Players.LocalPlayer.Character |
04 | local hum = char:WaitForChild( "HumanoidRootPart" ) |
05 | local pos = hum.Position |
06 | local gui = player.PlayerGui.mainGUI |
07 |
08 | function isInRegion 3 (region, point) |
09 | local relative = (point - region.CFrame.p) / region.Size |
10 | return - 0.5 < = relative.X and relative.X < = 0.5 |
11 | and - 0.5 < = relative.Y and relative.Y < = 0.5 |
12 | and - 0.5 < = relative.Z and relative.Z < = 0.5 |
13 | end |
14 |
15 | local nbh = { } |
Despite the player being in the area of "city", the popup appears as "notcity", so I think the problem is in the part that detects whether or not the player is in the region.
Help?
On line 5 you have local pos = hum.Position
this will hold the HumanoidRootPart current position which is used on line 28 but never updated to hold the current player position.
You need to access the position each time you are checking the players location.
01 | while true do |
02 | wait( 3 ) |
03 | local plrPos = hum.Position -- get the player position each time |
04 | for _, v in pairs (nbh) do |
05 | if isInRegion 3 (v.coords, plrPos) then -- |
06 | loc = v.name |
07 | else |
08 | loc = "notcity" |
09 | end |
10 | end |
11 | if loc ~ = temploc then |
12 | ~~make popup appear~~ |
13 | temploc = loc |
14 | end |
15 | end |
This should fix your position issue but you might be better off just checking the x,y,z of the Vector3.
Hope this helps.