Over here, a GUI should pop up only visible by you nobody else (that goes for everyone else) whenever you get close to another player in the game. The problem is, it loops through all the players and just picks one for some reason. How can I make it so it works for all players? Heres my code. Help would be greatly appreciated :)
Edit: It works fine with the print function, just shows the GUI for one of the players which is weird
while true do wait() for i, v in pairs(game.Players:GetPlayers())do local magnitude = (player.Character.Head.Position - v.Character.Head.Position).magnitude if magnitude < 10 and v.Name ~= player.Name then print("You are next to ")..v.Name billboard.Enabled = true else billboard.Enabled = false end end end
If you can't figure it out I have an uncopylocked place that includes the same thing, if you have time, please look at it [https://www.roblox.com/games/914378398/Magnitude-Between-Players]
You're making the billboard gui unenabled even though it may have already been enabled by someone else. I'm asumming you do know that for i, v in pairs(game.Players:GetPlayers())do
iterates through every player in no specific order. This means that with your current script, even if it finds a player close to you and enables the gui, the for loop will still keep going and the next player that 'v' becomes might not be close to the player, thus unenabling the gui even though there is a nearby player. This is why the gui only pops up for only one player; that player must the last player that the for loop checks for, thus it doesn't unenable the gui because it doesn't move on to find any player that is not nearby. You could easily fix this with an if statement that checks for a variable after the for loop that unenables the gui if the loop didn't find any close players like so:
while true do wait() local closeplayers = nil --Always reset to no players after the loop ends for i, v in pairs(game.Players:GetPlayers()) do local magnitude = (player.Character.Head.Position - v.Character.Head.Position).magnitude if magnitude < 10 and v.Name ~= player.Name then print("You are next to "..v.Name) --Also, this line was written wrong billboard.Enabled = true closeplayers = v.Name --If player found, change the variable end end if closeplayers == nil then --If there are no close players, set enabled to false billboard.Enabled = false end end
Hope that helps
Line 6; Didn't you mean "String" .. v.Name? :p
You also FORGOT TO DEFINE BILLBOARD!
Thank you, everyone, very much! Best answer here ever! See y'all later on and have a good night! This answer was brought to you by TheeDeathCaster! Thank you for readin! NOW STOP READIN.