Gui Kill Log TextLabel Resize Help

Hey, I’m currently scripting a gui kill log for when a player kills another player. The problem is I have no idea how to do this, but I have tried to tackle it with one method(it unfortunately isn’t consistent and doesn’t always work properly).

KillLog

My current method is using the TextBounds and checking for no changes in a loop of resizing. This only works part of the time. I’d also like to know if there is a more efficient way to do this.

Notes

  1. I’m using Scale and not Offset for sizing.
  2. TextWrapping and TextScaled are on
  3. Because of the statement above, TextFits for detecting doesn’t seem like an option.

So is there a better way to do this?

I had to read this twice, why aren’t you using offset? If you are trying to do a kill log you shouldn’t be trying to fit all of their username anyways. Best way to do it would to turn off textScaled, and use offset.

I’m aware of that method but I’d like to know if it’s possible with textScaled instead using offset and TextFits.

TextScaled automatically resizes your text according to the size of the box, but not the box itself. If you are only using offset and not scale, the box will not resize according to the window’s size and thus the text has no reason to be scaled either. TextFits is a read-only property describing whether the text fits within the text box or not.

Perhaps you’re looking for some kind of custom behaviour or other mannerism to accomplish you goal? Perhaps converting offset to scale after all (which truthfully one should be using scale for most UIs)? That’s the only real method I know. There might be something out there for this, I don’t know.

Quick question… do you want the {names} + {death cause} to be on the left side of the frame, or on the right?
I’ll come up with a solution shortly after I just know that bit.

I decided to write a script without the requested information.

This is a script with some easily use-able functions I wrote in it.

  • The primary function is: newLog(PlayerName1, ImageId, PlayerName2).
    PlayerName1 is the name of the person who’s featured on the left,
    ImageId is the ImageId of the weapon/death cause,
    PlayerName2 is the name of the person who’s featured on the right.

  • The secondary function is: updateLog(frame).
    frame is the frame that contains all the textlabels and the imagelabel that got made with newLog().
    tip: update the frame with updateLog() whenever the TextSize get’s changed with TextScaled

Here’s the full script:

--// Config
local screenEdgeOffset = 15 --// The amount of offset the first textlabel has from the screen edge on the left (in pixels)

local offsetSpace = 10 --// in pixels

function updateLog(frame) --// Updates the log to prevent the frames from overlapping

local imageLabel, plr1, plr2 = frame:WaitForChild("Image"), frame:WaitForChild("Player1"), frame:WaitForChild("Player2")

--//// Sizes

--// PlayerName1

plr1.Size = UDim2.new(0, plr1.TextBounds.X + offsetSpace, plr1.Size.Y.Scale, 0)

--// PlayerName2

plr2.Size = UDim2.new(0, plr2.TextBounds.X + offsetSpace, plr2.Size.Y.Scale, 0)

--//// Positions

--// PlayerName1

plr1.Position = UDim2.new(0, screenEdgeOffset, plr1.Position.Y.Scale, 0)

--// ImageLabel

imageLabel.Position = UDim2.new(0, plr1.AbsoluteSize.X + plr1.AbsolutePosition.X, imageLabel.Position.Y.Scale, 0)

--// PlayerName2

plr2.Position = UDim2.new(0, imageLabel.AbsoluteSize.X + imageLabel.AbsolutePosition.X + offsetSpace, plr2.Position.Y.Scale, 0)

--// Frame Size

frame.Size = UDim2.new(0, plr2.AbsolutePosition.X + plr2.AbsoluteSize.X + offsetSpace, frame.Size.Y.Scale, 0)

end

function newLog(PlayerName1, ImageId, PlayerName2) --// PlayerName1 = Killer, ImageId = ImageId of i.e. the weapon, PlayerName2 = Killed

if not PlayerName1 or not PlayerName2 then error"missing names (logKill)" return end --// Ends the function if the names are missing

local frame = script:WaitForChild("Frame"):Clone() --// Making a copy of the template stored in the script

local imageLabel, plr1, plr2 = frame:WaitForChild("Image"), frame:WaitForChild("Player1"), frame:WaitForChild("Player2")

--// Setting properties (text & imageId)

plr1.Text = PlayerName1

plr2.Text = PlayerName2

if ImageId then --// Checks if an ImageId was provided, without this it would've returned an error

imageLabel.Image = ImageId --// For example "rbxassetid://0"

end

frame.Parent = script.Parent --// Whatever parent you wish it to have

updateLog(frame)

end

newLog("D3strat", nil, "ChuckXZ")

And here’s the place file with the script and necessary setup (StarterGui): killLogScript.rbxl (562.2 KB)

If you’ve got any questions whether it’s about the OP question or the script etc., then reply and I’ll get to you as soon as possible.

Thank you to everyone for their advice, but I have decided to use offset instead of textscale and textwrap from my original intention to get this done.

I would recommend the method I provided as offset wouldn’t scale or resize if the screen is little, big or medium… only a certain amount of pixels.