PlayerGui:GetGuiObjectsAtPosition() doesn't work?

i can’t tell whether i’m just doing this wrong, but no matter what i try, it just can’t detect any sort of guiobject (like a frame, or a textlabel) on every single frame

local function ShiftRewardLabelToTop(rewardlabel: TextLabel)
	local tweenGoal = {Position = UDim2.fromScale(0, 0)}
	
	local shiftTween = tService:Create(rewardlabel, shiftRewardLabelToTopTweenParams, tweenGoal)
	local fadeOutTween = tService:Create(rewardlabel, fadeOutTweenParams, {TextTransparency = 1})
	
	shiftTween:Play()
	
	task.spawn(function()
		FlashRewardLabel(rewardlabel)
	end)
	
	task.spawn(function()
		shiftTween.Completed:Wait()		
		task.wait(2)
		
		fadeOutTween:Play()
		fadeOutTween.Completed:Wait()
		
		rewardlabel:Destroy()
		shiftTween:Destroy()
		fadeOutTween:Destroy()
	end)
	
	while shiftTween.PlaybackState == Enum.PlaybackState.Playing do
		local textlabelsAtPosition = plrGui:GetGuiObjectsAtPosition(rewardlabel.Position.X.Scale, rewardlabel.Position.Y.Scale)
		
		print(textlabelsAtPosition) -- gives {} :((
		
		for _, guiObject in textlabelsAtPosition do
			if not guiObject:IsA("TextLabel") then continue end
			if guiObject.Name ~= "RewardLabel" then continue end
			
			shiftTween.PlaybackState = Enum.PlaybackState.Completed
			shiftTween:Cancel()
		end
		
		task.wait()
	end
end

1 Like

You’re using the scale values, whereas I believe GetGuiObjectsAtPosition uses pixel offset. You can try to use rewardLabel.AbsolutePosition.X and rewardLabel.AbsolutePosition.Y instead.

1 Like

that didnt’ do the trick, unfortunately :sob:

What’s the script actually trying to achieve? Is the rewardLabel the “Shombler killed | +25XP…” thing or the “+48”?

You could try running a test script by placing a 1x1 pixel gui somewhere on your screen and running the GetGuiObjectsAtPosition at that position. If that’s working fine, then you know it’s something to do with the positions.

it’s supposed to stop the shift tween if the textlabel collides with an already existing text label

so they don’t overlap each other

theres probably a much better way to stop them colliding because if ur using the scrollingframe structure i told u about in a different post u can just put a blank frame in to the layout when the new label is created to create a gap and destroy it when u parent the label to the scrollingframe

itd be much more performance friendly too

2 Likes

i’m gonna be honest the explanation you gave me is very confusing and i literally do not understand it

can you give me an example :sob:

Try subtracting the rewardlabel’s position with the GuiInset, like so:

local GuiService = game:GetService("GuiService")

local function ShiftRewardLabelToTop(rewardlabel: TextLabel)
	local tweenGoal = {Position = UDim2.fromScale(0, 0)}
	
	local shiftTween = tService:Create(rewardlabel, shiftRewardLabelToTopTweenParams, tweenGoal)
	local fadeOutTween = tService:Create(rewardlabel, fadeOutTweenParams, {TextTransparency = 1})
	
	shiftTween:Play()
	
	task.spawn(function()
		FlashRewardLabel(rewardlabel)
	end)
	
	task.spawn(function()
		shiftTween.Completed:Wait()		
		task.wait(2)
		
		fadeOutTween:Play()
		fadeOutTween.Completed:Wait()
		
		rewardlabel:Destroy()
		shiftTween:Destroy()
		fadeOutTween:Destroy()
	end)
	
	while shiftTween.PlaybackState == Enum.PlaybackState.Playing do
		local position = rewardlabel.AbsolutePosition - GuiService:GetGuiInset()
		local textlabelsAtPosition = plrGui:GetGuiObjectsAtPosition(position.X, position.Y)
		
		print(textlabelsAtPosition) -- gives {} :((
		
		for _, guiObject in textlabelsAtPosition do
			if not guiObject:IsA("TextLabel") then continue end
			if guiObject.Name ~= "RewardLabel" then continue end
			
			shiftTween.PlaybackState = Enum.PlaybackState.Completed
			shiftTween:Cancel()
		end
		
		task.wait()
	end
end

@notsad2 Fixed a typo


@notsad2 Just checking to see if the code worked or not, since I haven’t yet received a reply :slight_smile::+1:

1 Like

sorry :<

ok so if ur gonna use the scrolling frame method:

  • Set up a scrolling frame with a ui list layout so that when u parent a label to it it appears the exact same as if no label was parented to it (visually) so like changing cell size and things (you’ll probably need UIAspectRatioConstraints to size them consistently across devices)
  • When a new label is to be tweened into position, parent a transparent frame to the ScrollingFrame the same size as the label so it effectively creates a “gap” for the new label to slot in
  • Tween the new label in
  • When the tween is done, remove the blank frame and parent the new label to the scrolling frame

this makes it look like you positioned it perfectly into place without having to create your own UIListLayout system

  • put a scrolling frame into the already-existing frame, insert a ui list layout into it,
  • when you gain a reward, clone a transparent frame the size of the rewardlabel, and parent it to the scrollable frame to create a gap
  • tween the label to the top… but won’t thisj ust bypass the gap entirely?
  • on tween completed, remove the transparent frame and parent the reward label to the scrolling frame

won’t the tween just bypass the gap entirely?
#confused

You need to take the topbar inset into account

oh wait i just had an idea
can you put the textlabel inside of a frame and tween the text label with positions relative to the frame until it is positioned correctly? that way u can just parent the frame and tween in the textlabel

the tween shouldn’t bypass the gap because if u do the positions correctly then it will look like its slotting right in

i’m already doing that
image

(They get cloned and parented to the frame)

this section confuses me tho

relative to the frame? huh? why?

boo

it hasn’t fixed :sob:
i forgot to reply sorry

ok so you know when you make a gui object and you set the scale part of its size?

so if u did this:
image
image
it takes up the whole screen?

Try making a frame with 0.5 size, like this:
image



and put another frame inside it with 1 size:
image
image

you see how now it doesn’t take up the whole screen, but only half?

This is because it’s set to 1 scale relative to its parent frame, so when we set it to 1 it’s only as big as it’s parent. Of course, if we make it larger, we can make it bigger than the parent, like this:
image






but the secondary frame is relative in size to its parent, so what im saying is you’ll need to change the sizes of the frame inside the scrolling frame and the label so they’re different if you’re going to use the scale property. Using offset property of UDim2 will make it pixels size, which means you could make them the same but you’ll need to scale them down across devices.

(i meant each textlabel has its own frame btw)

Try storing the rewardlabels inside of a table, which would allow you to offset their positions when a new rewardlabel is created, like so:

local rewardlabels = {}

local rewardlabelOffset = UDim2.fromScale(0, 0.1) -- You'll need to adjust this value according to the rewardlabel's size

local function ShiftRewardLabelsDown()
	for rewardlabel in rewardlabels do
		rewardlabel.Position += rewardlabelOffset
	end
end

local function ShiftRewardLabelToTop(rewardlabel: TextLabel)
	task.spawn(ShiftRewardLabelsDown)

	local shiftTween = tService:Create(
		rewardlabel,
		shiftRewardLabelToTopTweenParams,
		{Position = UDim2.fromScale(0, 0)})
	local fadeOutTween = tService:Create(
		rewardlabel,
		fadeOutTweenParams,
		{TextTransparency = 1})

	shiftTween:Play()
	rewardlabels[rewardlabel] = true

	task.spawn(FlashRewardLabel, rewardlabel)

	task.spawn(function()
		shiftTween.Completed:Wait()
		task.wait(2)

		fadeOutTween:Play()
		fadeOutTween.Completed:Wait()

		rewardlabel:Destroy()
		shiftTween:Destroy()
		fadeOutTween:Destroy()
		rewardlabels[rewardlabel] = nil
	end)
end

why a scrollable frame, can’t it just be a regular frame?

oh yeah true sorry im just so used to only using uilistlayouts on scrollingframes

i mean if u want the player to scroll their notifications go ahead but yeah ur right
just make sure to set the AutomaticCanvasSize to Y

1 Like

wowzies, that’s so cool…

it works

sorry :uk: but it wasn’t you this time :pensive:

1 Like

stupid docs told me that getguiobjectsatposition already accounts for inset

now im mad :mad:
(im grinding solutions on the forum)

1 Like