Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[SOLVED] How do I solve this problem with TextBounds?

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!

8 comments

0

2 Up votes. This Question should be answered. I'll up vote the right answer as well.

1

Tsk, tsk. I remember when as soon as you posted a script with more than 30 lines, everyone hated you. This is unfair.

0

Is this a Script or a LocalScript?

0

Also, what errors did you find when pressing F9 (opening dev console)

0

@LordDragonZord; it's all about context. This script may be 50 lines long, but a lot of those lines are only setting properties of newly created objects.

0

@OP; Is this a LocalScript, and is Filtering enabled?

0

@adark, that's no fair, I deserve those 20+ reputation back.

0

@TheDeadlyPanther, There are no errors in the dev console, @ALL This is in a Server Script (normal script), @adark Filtering is disabled.

2 answers

✓ Accepted answer

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.

4 comments

0

How could I actually fix this, I already have everything in 1 script, how could I get a local script to send the data of the text bounds back to the script? Also is it possible to use module scripts to do get text bounds?

0

Ignore that, I tried it, converted my script to a local script and edited it to work with the change. Thanks for the help!

0

You might want to edit {Still Unanswered} out of the title now btw

0

xD Did it, a bit late but at least it won't confuse people.

This discussion is preserved as it was. New answers, comments, and votes are closed.