game.ReplicatedStorage.Events.PlayerJoin.OnClientEvent:Connect(function(player)
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("TextLabel") then
if v.BeingUsed.Value == false then
v.Text = "-"..player.Name
end
end
end
end)
Script.Parent is the frame in which the script itself and all of the image labels are contained in. Second. there are other objects which are not textlabels inside the frame. There are also multiple textlabel.
Because I’m trying to make a player list. Therefore all the textlabels will need to be changed at some point but not all of them at the same time just from one player joining.
In terms of a PlayerList, there is probably more efficient ways to go about this. Have you tried just cloning a new object when a player joins and editing the text label from there?
Either way, for your specific issue you could maybe try adding in a Value which checks if we’ve already changed one TextLabels value like below.
game.ReplicatedStorage.Events.PlayerJoin.OnClientEvent:Connect(function(player)
local found = false
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("TextLabel") then
if v.BeingUsed.Value == false then
if found == false then
found = true
v.Text = "-"..player.Name
end
end
end
end
end)
There are definitely more efficient ways to do that, but as for the shortest way whilst still following the guidelines with your script I believe it’s the quickest and easiest change you could make. In terms of reliability, I’d recommend making sure that once you’ve found a TextLabel, you set the v.BeingUsed's value to be true, that way once another player joins it won’t be overwritten.
game.ReplicatedStorage.Events.PlayerJoin.OnClientEvent:Connect(function(player)
local found = false
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("TextLabel") then
if v.BeingUsed.Value == false then
if found == false then
found = true
v.Text = "-"..player.Name
v.BeingUsed.Value = true
end
end
end
end
end)
I checked the value in studio and it’s not being set to true for some reason
No no, I mean what are you checking to see if the BoolValue has changed? Are you checking your PlayerGui, or are you checking the games StarterGui? I went ahead and tested the script and it seems to work fine if you check the PlayerGui.
game.ReplicatedStorage.Events.PlayerJoin.OnClientEvent:Connect(function(player)
for i,v in pairs(script.Parent:GetChildren()) do
if v:IsA("TextLabel") then
if v.BeingUsed.Value == false then
v.Text = "-"..player.Name
break --Break out of loop.
end
end
end
end)
Add a break statement to the loop such that the loop is broken out of.