Problem with local character position

In a game I’m working on, we have a portal system, which allows players to teleport from one location to another. Ex. doorways, entrances, etc.

I’m using magnitude to calculate how close the player is to the specific “portal parts” on the client, and, up until a few days ago, the code was working completely fine. Also note, I did not change any of this code, it just stopped working a few days ago. The problem is that you can use any portal one time, but after that, the UI doesn’t appear on any doorway and you can’t use any of the portals.

So I did a lot of debugging since the problem was not obvious to me, and here’s what I found out. The problem is with the if statement where it is checking if the magnitude of the local player is close enough to the position of any given portal part. So, I went to the portion of code on the server where it physically moves your character, and commented it out, making the character not move when they use a portal. What I discovered is, is that when the player does not move, the magnitude if statement will remain working and allow you to keep “using” more portals (even though they don’t move you).

I also tried moving the player locally and that still would not work.

Here is the code for checking if the local player is near the portal (note that it is in a renderstepped loop):

inPortalRange = false
for x, y in pairs (PortalParts) do
    if (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - y.Position).Magnitude <= PortalRange and inPortalRange == false and ChatName == "" then
        PortalOut = y.Portal.Value
        script.Parent.Portal.Visible = true
        local world = workspace.CurrentCamera:WorldToScreenPoint(y.Position)
        script.Parent.Portal.Position = UDim2.new(0, world.X - 75, 0, world.Y - 20)
        inPortalRange = true
    end
end

Has anyone else been experiencing something like this, or am I just doing something really stupid?

2 Likes