Log in to vote

Why is my gui not working with magnitude when two people play??

Asked by
L30N_C 22
8 days ago

Ok so i am making a shop. Everything is fine. I am using magnitude for the shop to open. The magnitude is scripted in a localscript inside a gui where the shop comes up.

But when two people play the game, the magnitude stops working and gets buggy and stuff.

I cant solve this problem myself so i figured to ask you guys.

Here is the script:

repeat wait() until game.Players.LocalPlayer.Character

while wait() do
    for i, v in pairs(game.Players:GetChildren()) do
        if (v.Character.Head.Position - detection.Position).magnitude <= 10 then
            game.Players.LocalPlayer.PlayerGui.Shop.TextButton.Visible = true
            game.Players.LocalPlayer.PlayerGui.Shop.TextButton.Visible = false
            camera.CameraType = Enum.CameraType.Custom

btw when you walk out from the magnitude the camera resets.

1 answer

Log in to vote
Answered by 7 days ago

The for loop checks for every player, while the code inside the if statement scope opens up the menu for the local player the script is running on. Therefore, whenever any player is within the minimum magnitude, the shop menu opens for every player. As this is a local script and local scripts get replicated across every client, the solution is to check for only the local player's character.


Answer this question