So, I'm making a custom chat, but instead of making it simple I want to have the player's name a different color/font to the rest of the message. This somehow works perfectly in studio but does not work properly in online mode as seen in this place. How do I fix this problem, here's my function which returns no errors, works perfectly in studio but not in online mode:
function addMessage(speaker,msg,chat,color) for i,v in pairs(chat:GetChildren()) do if v:IsA("Frame") and string.sub(v.Name,1,7) then v.ActualPosition.Value = v.ActualPosition.Value-32 v:TweenPosition(UDim2.new(0,5,0,v.ActualPosition.Value),"Out","Sine",0.5,true) v.Name = "Message"..tostring(tonumber(string.sub(v.Name,8))+1) if v.Name == "Message6" then v:TweenPosition(UDim2.new(0,5,0,-62),"Out","Sine",0.5,true) game:GetService("Debris"):AddItem(v,0.5) end end end local ChatFrame = Instance.new("Frame",chat) ChatFrame.Name = "Message1" ChatFrame.BackgroundTransparency = 1 ChatFrame.Position = UDim2.new(0,5,0,149) ChatFrame.Size = UDim2.new(0,0,0,32) local ActualPosition = Instance.new("IntValue",ChatFrame) ActualPosition.Name = "ActualPosition" ActualPosition.Value = 149 local Name = Instance.new("TextLabel",ChatFrame) Name.Name = "Name" Name.BackgroundTransparency = 1 Name.TextColor3 = color Name.TextStrokeTransparency = 0.5 Name.Font = "SourceSans" Name.FontSize = "Size18" Name.Text = speaker Name.Size = UDim2.new(0,Name.TextBounds.X,0,Name.TextBounds.Y) Name.ZIndex = 2 local Message = Instance.new("TextLabel",ChatFrame) Message.Name = "Message" Message.BackgroundTransparency = 1 Message.TextColor3 = Color3.new(255,255,255) Message.Font = "SourceSansLight" Message.FontSize = "Size18" Message.TextXAlignment = "Left" Message.TextYAlignment = "Top" Message.TextWrapped = true Message.Text = msg Message.Size = UDim2.new(0,350,0,36) Message.Position = UDim2.new(0,Name.TextBounds.X+2,0,0) Message.ZIndex = 2 local Shadow = Message:Clone() Shadow.Parent = Message Shadow.TextColor3 = Color3.new(0,0,0) Shadow.Position = UDim2.new(0,-1,0,1) Shadow.ZIndex = 1 end
If you really want to see the rest of the script go here, although I don't see any reason why the rest of it would affect it. THIS IS IN A SERVER SCRIPT!
TextBounds cannot be calculated by the server and is not replicated to it either -- you'll have to use a local script to read it. You can observe this behavior in a simple environment by starting a test server with a test player, adding a GUI and a TextLabel to the player's PlayerGui, setting its text to anything, and then looking at the TextBounds property on both the server and client. Also, if you have an old plugin that inserts a NetworkServer to use HTTPService (you no longer need to do this to use HTTPService in plugins), it will break TextBounds because Studio will think it's a server -- this is the way I initially discovered this in fact.
This kind of gotcha should be listed on the wiki, but it isn't. I'll ask someone to add it onto the TextBounds pages for TextBoxes, TextLabels, and TextButtons. Edit: Thank TheGamer101 for adding this to the appropriate pages.