Problems with player tracker

Hello. :wave:

I want to be able to have it when a certain rank joins then you will be able to track the player.

However, I have been running into this issue, whenever you are in-game before the player joins then you will not be able to track the player:
https://gyazo.com/d4a0c7f8c0d0ea30dc864a0ace130ae6

I have tried making a “refresh” for the GUI, but I am not very experienced in that, so it would just break when I tried to make one.

Variables:

local Debris = game:GetService("Debris")

local Testing = true

wait(1)

repeat wait() until script:IsDescendantOf(game)

local Tracker = script.Parent:WaitForChild("Tracker")
local VIPFrame = Tracker:WaitForChild("VIPFrame")
local Template = script:FindFirstChild("Template")
local TrackerSize = Tracker.Size

local Opened = false

Tracker.Size = UDim2.new(0,0,0,0)
Tracker.Visible = false

local VIP = {}

local Duration = 15
local CooldownTime = 30 
local Selected = ""
local Cooldown = 0 

Part of the main code:

game.Players.PlayerAdded:Connect(function(Player)
	if Player:GetRankInGroup(2744682) >= 15 then
		Tracker.VIPFrame.TextButton:Destroy()
		if Player == game.Players.LocalPlayer then return end
		if not VIP[Player.UserId] then
			local TemplateClone = Template:Clone()
			TemplateClone.Name = Player.Name
			TemplateClone.Text = Player.Name
			TemplateClone.Parent = VIPFrame
			table.insert(VIP, Player.UserId, TemplateClone)
		end
	end
end)

for _, v in pairs(VIPFrame:GetChildren()) do 
	if v:IsA("TextButton") then
		v.MouseButton1Click:Connect(function()
			if game.Players:FindFirstChild(v.Name) then
				Selected = v.Name
				Tracker.TrackVIP.Text = 'Track '.. v.Name
			end
		end)
	end
end

If you need to see more code, just tell me.

Thank you.

1 Like

The pairs loop is only running once, upon execution of the script, and if any players join after the loop already ran then clicking on the button won’t do anything. You could try put the MouseButton1Click event inside of PlayerAdded

I’m not exactly sure how your system works but it should look something like this

local Players = game:GetService("Players")

local function SetupTracker(Player)
	if Player:GetRankInGroup(2744682) >= 15 then
		Tracker.VIPFrame.TextButton:Destroy()
		if Player == Players.LocalPlayer then return end
		if not VIP[Player.UserId] then
			local TemplateClone = Template:Clone()
			TemplateClone.Name = Player.Name
			TemplateClone.Text = Player.Name
			TemplateClone.Parent = VIPFrame
			table.insert(VIP, Player.UserId, TemplateClone)

			-- Find the button in the template
			local Button = TemplateClone:FindFirstChildOfClass("TextButton")
			if Button then
				Button.MouseButton1Click:Connect(function()
					if Players:FindFirstChild(Button.Name) then
						Selected = Button.Name
						Tracker.TrackVIP.Text = 'Track '.. Button.Name
					end
				end)
			end
		end
	end
end

-- setup for all players already in the game
for i, Player in pairs(Players:GetPlayers()) do
	SetupTracker(Player)
end

-- and for any players that join the game
game.Players.PlayerAdded:Connect(SetupTracker)

Hello, sorry for the late response, it is still not working, I might have forgotten to tell you that all of this is in a local script, I don’t know if that would change anything or not, but if it does, what would I need to put in a server script?

This is what the GUI components are:
https://gyazo.com/c3012d4297c3a53206c564616ac930ac

As well as the removing of the player:

game.Players.PlayerRemoving:Connect(function(Player)
	if VIPFrame:FindFirstChild(Player.Name) then
		VIPFrame[plr.Name]:Destroy()
		if Selected == Player.Name then
			Selected = nil
			Tracker.TrackVIP.Text = 'Nobody Selected.'
		end
		table.remove(VIP, Player.UserId)
	end
end)

– dmksa123