I’m modifying a rank UI script and changing the TextColour of the text when it displays a certain message, but I can’t because it comes up with this error:
You are trying to set TextColor to the Group Name which is only a string got from a :GetGroupsAsync() method. Because TextColor is a property in a TextLabel You need to set it while creating that Label.
--[...] Lines 67-72
for i,v in pairs(Divs) do
local t = Template:Clone()
--You need do do this inside that for, after You cloned the template
t.Parent = Tip.Divisions
t.Position = UDim2.new(0, 0, 0, 10 * (i - 1))
t.Text = v
end
--[...]
Technically Yes, but if you have in Text a Group Name + Group Rank You’ll need to use string.find to find the name of group or You can modify the GetUserDivs function to return Text and TextColor
No, you need to pass to the function 2 strings, first the string that will search for a 2nd string which in your case will be group name. And You do group name conversion in the GetUserDivs function.
--For example t.Text == "RAF Police - [TR] Trainee Constable"
if string.find(t.Text, "RAF Police") then
t.TextColor = Color3.fromRGB(255,255,255)
end
I’ve just put your reply into context, does this look right?
mouse.Move:connect(function()
if mouse.Target then
local tPlayer = game:service("Players"):GetPlayerFromCharacter(mouse.Target.Parent)
if tPlayer then
Tip.Visible = true
Tip.Divisions.Visible = true
CurrentTarget = tPlayer
local Divs = GetUserDivs(tPlayer)
Tip.Divisions:ClearAllChildren()
Tip.Text = tPlayer.Name
for i,v in pairs(Divs) do
local t = Template:Clone()
t.Parent = Tip.Divisions
t.Position = UDim2.new(0, 0, 0, 10 * (i - 1))
t.Text = v
if t.Text == "[RAF] Royal Air Force Police" then
t.Text = "RAF Police"
elseif
t.Text == "RAF || The Royal Air Force" then
t.Text = "Royal Air Force"
elseif
t.Text == "[RAF] No 1 group" then
t.Text = "No II"
else
if t.Text == "[RAF] Royal Air Force Regiment" then
t.Text = "RAF Regiment"
t.TextColor = Color3.fromRGB(10, 170, 130)
end
wait(.1)
if string.find(t.Text, "RAF Police") then
t.TextColor = Color3.fromRGB(25, 175, 255)
elseif
string.find(t.Text, "Royal Air Force") then
t.TextColor = Color3.fromRGB(10, 110, 255)
elseif
string.find(t.Text, "No II") then
t.TextColor = Color3.fromRGB(50, 100, 225)
else
if string.find(t.Text, "RAF Regiment") then
t.TextColor = Color3.fromRGB(10, 170, 130)
end
end
end
end
else
Tip.Visible = false
end
end
end)
Not quite. If You didn’t make changes to the GetUserDivs function it already returns a table containing a string like "RAF Police - [TR] Trainee Constable"
mouse.Move:connect(function()
if mouse.Target then
local tPlayer = game:service("Players"):GetPlayerFromCharacter(mouse.Target.Parent)
if tPlayer then
Tip.Visible = true
Tip.Divisions.Visible = true
CurrentTarget = tPlayer
local Divs = GetUserDivs(tPlayer)
Tip.Divisions:ClearAllChildren()
Tip.Text = tPlayer.Name
for i,v in pairs(Divs) do
local t = Template:Clone()
t.Parent = Tip.Divisions
t.Position = UDim2.new(0, 0, 0, 10 * (i - 1))
t.Text = v
if string.find(t.Text, "RAF Police") then
t.TextColor = Color3.fromRGB(25, 175, 255)
elseif
string.find(t.Text, "Royal Air Force") then
t.TextColor = Color3.fromRGB(10, 110, 255)
elseif
string.find(t.Text, "No II") then
t.TextColor = Color3.fromRGB(50, 100, 225)
else
if string.find(t.Text, "RAF Regiment") then
t.TextColor = Color3.fromRGB(10, 170, 130)
end
end
end
end
else
Tip.Visible = false
end
end
end)
I’ve just run the game with a friend and it says I need a BrickColor. Quick unrelated question, why do I need to apply BrickColor instead of Color3 when changing a TextColor value?
It’s refreshing because You update it everytime when moving cursor. To fix the issue you need to add a check if script already shown that player ranks.
And the second issue, maybe try split Group Name and the Group Rank and perform the checks
On the video I didn’t see that group names are getting converted, so try to add Group name conversion in the text label creation too.
local split = string.split(t.Text," - ")
local GroupName = split[1]
if GroupName then
local Rank = split[2]
if GroupName == "[RAF] Royal Air Force Police" then
t.TextColor3 = Color3.new(255,255,255)
t.Text = "RAF Police - " .. Rank
--And etc.
end
end
I’ve fixed the refreshing bit, but the displayed name doesn’t change to the one I tell it to, like I told it to
convert [RAF] Royal Air Force Police to RAF Police but it still shows [RAF] Royal Air Force Police.
Mkay, try this code and let me know if this works:
local CurrentTarget = nil
local Template = script:WaitForChild("Template")
while 1 do
for _,group in pairs(DivisionList:GetCurrentPage()) do
do
Divisions[group.Id] = group
end
end
if DivisionList.IsFinished then
break
end
DivisionList:AdvanceToNextPageAsync()
end
print("got divisions")
GetUserDivs = function(tPlayer)
local PlayerGroups = game:service("GroupService"):GetGroupsAsync(tPlayer.userId)
local ReturnT = {}
if not Cache[tPlayer.Name] then
for i,v in pairs(PlayerGroups) do
if Divisions[v.Id] then
table.insert(ReturnT,{
GroupName = v.Name,
Rank = v.Role
})
end
end
Cache[tPlayer.Name] = ReturnT
else
ReturnT = Cache[tPlayer.Name]
end
return ReturnT
end
mouse.Move:connect(function()
if mouse.Target then
local tPlayer = game:service("Players"):GetPlayerFromCharacter(mouse.Target.Parent)
if tPlayer then
if CurrentTarget == tPlayer then return end
Tip.Visible = true
Tip.Divisions.Visible = true
CurrentTarget = tPlayer
local Divs = GetUserDivs(tPlayer)
Tip.Divisions:ClearAllChildren()
Tip.Text = tPlayer.Name
for i,v in pairs(Divs) do
local t = Template:Clone()
t.Position = UDim2.new(0, 0, 0, 40 * (i - 1))
if v.GroupName == "[RAF] Royal Air Force Police" then
t.Text = "RAF Police - " ..v.Rank
t.TextColor3 = Color3.fromRGB(25, 175, 255)
elseif v.GroupName == "RAF || The Royal Air Force" then
t.Text = "Royal Air Force - " ..v.Rank
t.TextColor3 = Color3.fromRGB(10, 110, 255)
elseif v.GroupName == "[RAF] No 1 group" then
t.Text = "No II - " ..v.Rank
t.TextColor3 = Color3.fromRGB(50, 100, 225)
elseif v.GroupName == "[RAF] Royal Air Force Regiment" then
t.Text = "RAF Regiment - " ..v.Rank
t.TextColor3 = Color3.fromRGB(10, 170, 130)
end
t.Parent = Tip.Divisions
end
else
Tip.Visible = false
CurrentTarget = nil
end
end
end)
while wait() do
if mouse.Target then
Tip.Position = UDim2.new(0,mouse.X,0,mouse.Y) + UDim2.new(0,20,0,5)
end
end
Okay it works well, it’s just there’s a large gap between the groups, which I think is caused because the other groups don’t show up and the space is in a way ‘reserved’ for that certain group name. Is there any fixable way? https://gyazo.com/3dc3e20c82dcba7664104278ed23e884