You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to remove a dot from my minimap system when the player leaves
What is the issue? Include screenshots / videos if possible!
I have a minimap system, everything works and I’m proud of it since I didn’t use any tutorials and I figured out a very easy formulae for it.
However, sadly I made a check for if the player left the game to remove one of their dots from every player’s playergui. But it doesn’t work. (Likely to me that GetChildren isn’t working properly)
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried indexing the player name instead, didn’t work. Tried switching around alot of things but in the end sadly nope.
local Debris = game:GetService("Debris")
-- Messages saying "Works" means that they print, "Fails" are the ones that don't print
local function RemovePlayerDot(RemovedPlayer)
for Every, Player in game.Players:GetPlayers() do
if Player and RemovedPlayer ~= nil then
print("Works")
local MapGui = Player.PlayerGui:FindFirstChild("MapGui")
if MapGui then
print("Works")
-- Below this line nothing prints
local NewDots = MapGui.MapFrame.NewDots:GetChildren()
for Every, Dot in NewDots do
print("Fails")
if Dot.Name == RemovedPlayer.UserId then
print("Fails")
Debris:AddItem(Dot, 0)
end
end
end
end
end
end
game.Players.PlayerRemoving:Connect(RemovePlayerDot)
If it fails, that means MapGui.MapFrame.NewDots has no children. Start the game in studio, switch to server view, and before leaving check if that has anything.
Yes I know this is the issue but, I’ve checked the player’s playergui countless times and it does have children! I’ll send you a screenshot of it in a moment*
To see if any of the children appear, if not the problem could be the children haven’t loaded in yet, so add a wait until the children load in also add wait for childs for mapGui, mapFrame, and newDots to be safe.
print(MapGui.MapFrame.NewDots:GetChildren())
task.wait(10) -- This is for testing purposes to see if it really isn't loaded in yet
print(MapGui.MapFrame.NewDots:GetChildren())
local NewDots = MapGui:WaitForChild("MapFrame"):WaitForChild("NewDots"):GetChildren()
for Every, Dot in NewDots do
print("Fails")
if Dot.Name == RemovedPlayer.UserId then
print("Fails")
Debris:AddItem(Dot, 0)
end
end
Also, instead of going thru every dot, since the name of the dots are the players id, you could just do MapGui.MapFrame.NewDots:FindFirstChild(tostring(RemovedPlayer.UserId)):Destroy()
I think in reality what is happening is that since you’re the only player in the server, the server either
A. Shutsdown before it can loop through the folder
B. Deletes the children as the server is being closed
Also a better way of doing this would to be putting the dots in a folder name being the players id or name then destroying the folder so all the dots delete.
If you are creating the dots on the client, they won’t replicate to the server. Only things in StarterGui will. You could use a RemoteEvent to get around this.
Subtle thing, you are comparing a string with a number, which causes a logic error (no output and does not stop the program running) as this comparison will always return false.
. Try if Dot.Name == tostring(RemovedPlayer.UserId) then
I tried this earlier a while ago myself before you handed the suggestion, I also thought this may have been an issue but the same issue was there. Nothing really changed.
Update everyone: A mix of @lavasance and @12345koip solutions worked! The problem was that I was setting the minimaps through names instead of userids, which was the real issue. And I had to use it from the client. Thanks.