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

My location popup script doesn't work?

Asked by 6 years ago

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:

01game.Players.LocalPlayer.CharacterAdded:Wait()
02local player = game.Players.LocalPlayer
03local char = game.Players.LocalPlayer.Character
04local hum = char:WaitForChild("HumanoidRootPart")
05local pos = hum.Position
06local gui = player.PlayerGui.mainGUI
07 
08function isInRegion3(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
13end
14 
15local nbh = {}
View all 38 lines...

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?

1 answer

Log in to vote
1
Answered by 6 years ago

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.

01while 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 isInRegion3(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
15end

This should fix your position issue but you might be better off just checking the x,y,z of the Vector3.

Hope this helps.

0
thanks. radusavin366 617 — 6y
Ad

Answer this question