So I am kind of confused how to explain this, so I hope you can understand this. How would I get which textbutton was not the text I wanted it to be, so then I could turn it into that text? For example;
local player = game.Players.LocalPlayer
local dict = player:GetFriendsOnline(200)
for i,friend in pairs(dict) do
print(friend.UserName.." from this script")
if friend then
if not script.Parent.plr.Text == friend.UserName or not script.Parent.plr2.Text == friend.UserName or not script.Parent.plr3.Text == friend.UserName or not script.Parent.plr4.Text == friend.UserName or not script.Parent.plr5.Text == friend.UserName or not script.Parent.plr6.Text == friend.UserName or not script.Parent.plr7.Text == friend.UserName or not script.Parent.plr8.Text == friend.UserName or not script.Parent.plr9.Text == friend.UserName or not script.Parent.plr10.Text == friend.UserName or not script.Parent.plr11.Text == friend.UserName or not script.Parent.plr12.Text == friend.UserName or not script.Parent.plr13.Text == friend.UserName or not script.Parent.plr14.Text == friend.UserName or not script.Parent.plr15.Text == friend.UserName or not script.Parent.plr16.Text == friend.UserName or not script.Parent.plr17.Text == friend.UserName then
--r would be the text chosen in the if statement
r.Name = friend.UserName
r.Text = friend.UserName
r.Visible = true
else
print("error getting players friend")
end
end
end
Sorry if this is confusing, I need help on this and it would be appreciated if you could help!
Here is what I am trying to achieve, this is a much better example.
local player = game.Players.LocalPlayer
local dict = player:GetFriendsOnline(200)
for i,friend in pairs(dict) do
print(friend.UserName.." from this script")
if friend then
if not script.Parent.plr.Text == friend.UserName or not script.Parent.plr2.Text == friend.UserName or not script.Parent.plr3.Text == friend.UserName or not script.Parent.plr4.Text == friend.UserName or not script.Parent.plr5.Text == friend.UserName or not script.Parent.plr6.Text == friend.UserName or not script.Parent.plr7.Text == friend.UserName or not script.Parent.plr8.Text == friend.UserName or not script.Parent.plr9.Text == friend.UserName or not script.Parent.plr10.Text == friend.UserName or not script.Parent.plr11.Text == friend.UserName or not script.Parent.plr12.Text == friend.UserName or not script.Parent.plr13.Text == friend.UserName or not script.Parent.plr14.Text == friend.UserName or not script.Parent.plr15.Text == friend.UserName or not script.Parent.plr16.Text == friend.UserName or not script.Parent.plr17.Text == friend.UserName then
--r would be the text chosen in the if statement
r.Name = friend.UserName
r.Text = friend.UserName
r.Visible = true
else
print("error getting players friend")
end
end
end
This is a bad approach. You could loop through them and check, but with your current method youâd have to do if not rr1.Text == textiwant then rr1.Text = textiwant ... A better approach would be with a loop:
local scriptParent = script.Parent -- no need to constantly check the parent, just use a variable
for i = 1, 5 do
local currentRR = scriptParent:FindFirstChild("rr" .. tostring(i))
if currentRR and currentRR.Text ~= textiwant then
currentRR.Text = textiwant
-- do whatever
end
end
Didnât work, this isnât going to be implementable in the script I provided to @goldenstein64 .
local player = game.Players.LocalPlayer
local dict = player:GetFriendsOnline(200)
for i,friend in pairs(dict) do
print(friend.UserName.." from this script")
if friend then
if not script.Parent.plr.Text == friend.UserName or not script.Parent.plr2.Text == friend.UserName or not script.Parent.plr3.Text == friend.UserName or not script.Parent.plr4.Text == friend.UserName or not script.Parent.plr5.Text == friend.UserName or not script.Parent.plr6.Text == friend.UserName or not script.Parent.plr7.Text == friend.UserName or not script.Parent.plr8.Text == friend.UserName or not script.Parent.plr9.Text == friend.UserName or not script.Parent.plr10.Text == friend.UserName or not script.Parent.plr11.Text == friend.UserName or not script.Parent.plr12.Text == friend.UserName or not script.Parent.plr13.Text == friend.UserName or not script.Parent.plr14.Text == friend.UserName or not script.Parent.plr15.Text == friend.UserName or not script.Parent.plr16.Text == friend.UserName or not script.Parent.plr17.Text == friend.UserName then
--r would be the text chosen in the if statement
r.Name = friend.UserName
r.Text = friend.UserName
r.Visible = true
else
print("error getting players friend")
end
end
end
How is it not implementable? Just get rid of your if statements and replace it with the loop. If you need to have the else statement if all of the text boxes match, then you can just set a variable to check if any of the textboxes matched:
local scriptParent = script.Parent -- no need to constantly check the parent, just use a variable
local noMatches = true
for i = 1, 5 do
local currentRR = scriptParent:FindFirstChild("rr" .. tostring(i))
if currentRR and currentRR.Text ~= textiwant then
noMatches = false
currentRR.Text = textiwant
-- do whatever
end
end
if noMatches then
print("error getting players friend")
end
Why canât you just replace âtextiwantâ with friend.UserName? The textiwant variable was just the example you used in your original post before you edited it.
local player = game.Players.LocalPlayer
local scriptParent = script.Parent
local noMatches = true
local dict = player:GetFriendsOnline(200)
for i,friend in pairs(dict) do
for i = 1, 5 do
local currentRR = script.Parent:FindFirstChild("plr" .. tostring(i))
if currentRR ~= friend.UserName then
noMatches = false
currentRR.Text = friend.UserName
end
end
if noMatches then
print("error getting players friend")
end
end
And an error formed;
[attempt to index local âcurrentRRâ (a nil value)
Thatâs because you got rid of the part of the script that checks if it exists. I have if currentRR and currentRR.Text ~= textiwant then because the if currentRR and wonât continue the if statement if currentRR is nil.
You would have to name the first plr labelâs name plr1, but I think this could work? At least it makes the if statement shorter.
local NUM_LABELS = 17
local Names = {}
for i = 1, NUM_LABELS do
local plrLabel = script.Parent["plr"..i]
Names[plrLabel.Text] = true
local lastText = plrLabel.Text
plrLabel:GetPropertyChangedSignal("Text"):Connect(function()
Names[lastText] = nil
Names[plrLabel.Text] = true
lastText = plrLabel.Text
end)
end
local player = game.Players.LocalPlayer
local dict = player:GetFriendsOnline(NUM_LABELS)
for i, friend in pairs(dict) do
print(friend.UserName.." from this script")
if friend and not Names[friend.UserName] then
local plrLabel = script.Parent["plr"..i]
plrLabel.Text = friend.UserName
end
end
Actually, probably not because the way it chooses the username and the way it finds the label to change is different.