for i,v in pairs(game.Players:GetPlayers()) do
local button = script.Playerbutton:Clone()
button.Text = v.Name
button.Name = v.Name
button.Parent = script.Parent.DampeningMF.ScrollingFrame
button.MouseButton1Click:Connect(function()
if workspace:FindFirstChild(button.Name) then
button.MouseButton1Click:Connect(function()
print(button.Name)
local targetplr = Players[button.Name]
print(targetplr.Name)
ReplicatedStorage.Events:WaitForChild("Pressed"):FireServer(plr, targetplr)
end)
end
end)
end
#How would I make this for i,v loop keep track of all the current players?
13 messages · Page 1 of 1 (latest)
Basically what I'm trying to do is make a list with all the current players, but whenever someone joins after I do, his name does not appear in the list
add the players name to a table every time it iterates through the loop
local table = {}
for i,v in pairs(game.Players:GetPlayers()) do
table.add(v)
local button = script.Playerbutton:Clone()
button.Text = v.Name
button.Name = v.Name
button.Parent = script.Parent.DampeningMF.ScrollingFrame
button.MouseButton1Click:Connect(function()
if workspace:FindFirstChild(button.Name) then
button.MouseButton1Click:Connect(function()
print(button.Name)
local targetplr = Players[button.Name]
print(targetplr.Name)
ReplicatedStorage.Events:WaitForChild("Pressed"):FireServer(plr, targetplr)
end)
end
end)
end
i think thats how you would do it
cant remember exactly
Oh yeah that might work, thank you
Because you need to update the list every time a player joi
Join*
game.Players.PlayerAdded:Connect(function(plr)
local button = script.Playerbutton:Clone()
button.Text = v.Name
button.Name = v.Name
button.Parent = script.Parent.DampeningMF.ScrollingFrame
button.MouseButton1Click:Connect(function()
if workspace:FindFirstChild(button.Name) then
button.MouseButton1Click:Connect(function()
print(button.Name)
local targetplr = Players[button.Name]
print(targetplr.Name)
ReplicatedStorage.Events:WaitForChild("Pressed"):FireServer(plr, targetplr)
end)
end
end)
end)
game.Players.PlayerRemoved:Connect(function(plr)
script.Parent.DampeningMF.ScrollingFrame:FindFirstChild(plr.Name):Destroy()
end)
(you cant
table.add(v)
You need to
local T = {}
table.insert(T,v)
)
i said i couldnt remember exactly
at the top i also defined the table btw