Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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
			else
			game.Players.LocalPlayer.PlayerGui.Shop.TextButton.Visible = false
			camera.CameraType = Enum.CameraType.Custom
		end
	end
end

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

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.