Help making a killfeed, using string.len?

I’m trying to make a kill feed that would look something like this. Currently at moment I just have a kill feed that says ‘Player1 Rifle Player 2’ But it’s only in the colour of the player who killed the other. I wanna be able to have 3 labels, one to the left which is the name and team colour of the player, one to the right with the name and team colour of the dead player and the middle to just be white, which has the name of the weapon.
I’m not sure how to size the labels properly though, as someone may have an excesively longer name compared to others. And in the example is has different size boxes depending how much room the text takes up. The text is also all the same size, but since I have text wrapped and scaled it can make certain names appear larger than others.

As can be seen here, the text on the right is forced to be incredibly small, but if you have a player with a shorter name then it’s really large and becomes almost impossible to balance it out completely.

string.len would give you the amount of characters in a string. The length of the graphic of that text depends on font, text size, etc.

Check out this service:
https://wiki.roblox.com/index.php?title=API:Class/TextService

Specifically:
https://wiki.roblox.com/index.php?title=API:Class/TextService/GetTextSize

1 Like

Using FontSize won’t matter won’t it if I have Wrapped and scaled ticked?

Just pick whatever value for font size and then determine the aspect ratio of the text’s size from the result (= x / y), then you can use that ratio to scale your labels correctly.

print(textService:GetTextSize('OnlyTwentyCharacters', 20, 'SourceSans', Vector2.new(5, 0.5)))

What would I enter into the Vector2? It wants to get the frames Size, but the frame has Offset and Scale, and I will only use scale

Or you can check the TextBounds property of the text label.

I genuinely have no clue what I’m doing :sweat_smile: I put in the vector2 for the frame as the frames absoultesize, and just guessing that that would change when the scaling changes. I don’t think I can use TextBounds as I plan on using the scripts to create the textlabels

You can make the text label from a script, change the font, font size, change the text, etc., and then you can get the TextBounds property afterwards, and change the size of the text label.

So how would I use the TextBounds to get the size of the label?

Whenever you change a property of the text label, let’s say, the text; the TextBounds property will automatically update, afterwards, you can use the X and Y dimensions of the TextBounds and update the text label’s size according to the TextBounds’.

Vector2.new(math.huge, math.huge) (i.e. unconstrained)

Regarding TextBounds: This is a silly way to solve the problem, GetTextSize is what you’re after.

1 Like

Ahh I think I’m maybe trying to bite off more than I can chew, too confusing for me at the moment

If you’ve already made changes to the text label’s properties (text, font, font size, etc.), then TextBounds is the way to go. Otherwise, use the TextService… but for me, I haven’t tried that service before. So I always use the TextBounds property.

I truly don’t know if it’d be the most efficient but couldn’t you just scale the text label based on the length of it

Tag.Size = UDim2.new(0,Tag.TextBounds.X,0,20) -- An example that changes the TextLabel to whatever textsize you're using

Then just use a UIListLayout that aligns all of the textlabels/images up to make a row.

I don’t want to use the offset when sizing things. Otherwise it’s impossible to make something big enough to read on xbox without filling the screen on an iphone

Okay? Then use scale. (Sorry for a late response)

I assume you’re using a frame (non scrolling) so I don’t see why this would be a problem?

I’ve read this post a few times and now decided to post this. Do you want the names in the kill-feed to be shortened or do you want it to appear as the same size?

Bump. Forgot to mention that you can use a module like Defaultio’s RichText ModuleScript to change a certain text’s color, font, font size, or even add image labels; you can also have bouncy animations, text fading in, etc. It’s really easy to use if you read the instructions, and check the samples Defaultio provided within the module script. All you need is just to add a frame where you want the text to go in, and then use this line in a script to fill the frame with the text, as long as you have the module required (local RichText = require(game.ReplicatedStorage.RichText):

RichText:New(TextFrame, "Hi there", {Font = "Cartoon", TextStrokeTransparency = 0.5}):Animate(true)

In case you don’t want the text to animate in (slowly fade in the letters), you can use :Show(false), I think that’s how you do it, I don’t remember.
(First argument: the frame that will be filled with the text, any size you change the frame into, the text will follow accordingly. Second argument: the text, self-explanatory. Third argument: properties (font, font size, text alignment, etc.))

Filling the text property with something like: <Color=Red> Player1 <Color=/> killed <Color=Blue> Player2 <Color=/> with <Img="Sword">, will color the Player1 text with the red color, and then cut the color so killed doesn’t show red too, instead it will be set to default, which is white; Player2 will be colored blue, cause we supplied it to be like that, and then we cut the color again so with will be colored white, and then we add an image afterwards showing the weapon Player1 used to kill Player2; in this case, it’s a sword. All of these can be found and modified in the module script.

I’ve been using this module script a lot, and it saved me a lot of time. I suggest giving it a try.

1 Like

I’ll give it a look :+1: thanks :smiley:

1 Like