How to get gui objects under a frame?

so what im trying to do is a mini game where the cyan frame moves forward and then backward, and when the player clicks his mouse the cyan frame stop moving, and then you check if the cyan frame is touching any of the green frames, but the problem is that its not working, i tried using

PlayerGui:GetGuiObjectsAtPosition(CyanFrame.Position.X.Offset, CyanFrame.Position.Y.Offset)

image

but its not working for some reason, heres the script:

local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")

local MovingFrame = script.Parent

local Info = TweenInfo.new(.85, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true,0)
local Goal = {Position = UDim2.new(0.969, 0,-0.282, 0)}

local Tween = TweenService:Create(MovingFrame, Info, Goal)

local function StartMoving()

	Tween:Play()

	local Loop = Tween.Completed:Connect(function()

		Tween:Play()

	end)
	
	return Loop
	
end

local Loop

Loop = StartMoving()

UserInputService.InputBegan:Connect(function(key)

	if key.UserInputType == Enum.UserInputType.MouseButton1 then
	
		Loop:Disconnect()
		Tween:Pause()
		
		print(game.Players.LocalPlayer.PlayerGui:GetGuiObjectsAtPosition(MovingFrame.Position.X.Offset, MovingFrame.Position.X.Offset))

		wait(.5)
		
		Loop = StartMoving()

	end

end)

any help will be appreciated

1 Like

It could be that you’ll need to use AbsolutePosition instead:

local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")

local MovingFrame = script.Parent

local Info = TweenInfo.new(.85, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true,0)
local Goal = {Position = UDim2.new(0.969, 0,-0.282, 0)}

local Tween = TweenService:Create(MovingFrame, Info, Goal)

local function StartMoving()

	Tween:Play()

	local Loop = Tween.Completed:Connect(function()

		Tween:Play()

	end)
	
	return Loop
	
end

local Loop

Loop = StartMoving()

UserInputService.InputBegan:Connect(function(key)

	if key.UserInputType == Enum.UserInputType.MouseButton1 then
	
		Loop:Disconnect()
		Tween:Pause()
		
		print(game.Players.LocalPlayer.PlayerGui:GetGuiObjectsAtPosition(MovingFrame.AbsolutePosition.X, MovingFrame.AbsolutePosition.Y))

		wait(.5)
		
		Loop = StartMoving()

	end

end)
1 Like

i did try that before posting this issue, but i tried it again anyways and it prints an empty table

The AbsolutePosition is dependant on the frame’s anchor point, so it might be the case that we need to offset the value according to the frame’s AbsoluteSize as well if the anchor point isn’t set to 0.5, 0.5

1 Like

i just checked, the cyan frame anchor point is (0.5,0.5) and all the green frames’ anchor points are (0,0) and the problem is still there

It could be happening due to the top-bar’s offset, so this might work:

local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")

local MovingFrame = script.Parent

local Info = TweenInfo.new(.85, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true,0)
local Goal = {Position = UDim2.new(0.969, 0,-0.282, 0)}

local Tween = TweenService:Create(MovingFrame, Info, Goal)

local function StartMoving()

	Tween:Play()

	local Loop = Tween.Completed:Connect(function()

		Tween:Play()

	end)
	
	return Loop
	
end

local Loop

Loop = StartMoving()

UserInputService.InputBegan:Connect(function(key)

	if key.UserInputType == Enum.UserInputType.MouseButton1 then
	
		Loop:Disconnect()
		Tween:Pause()
		
		print(game.Players.LocalPlayer.PlayerGui:GetGuiObjectsAtPosition(MovingFrame.AbsolutePosition.X, MovingFrame.AbsolutePosition.Y - GuiService:GetGuiInset().Y))

		wait(.5)
		
		Loop = StartMoving()

	end

end)
1 Like

it still dosent work for some reason, i thought maybe it was because i toggled on ignoreGuiInset but it still didnt work

1 Like

A test you can try is to compare the frame’s position and absolute position with the mouse’s position, and alternatively setting the offset value manually to a value such as 36


@TypicalCEO I found a post on the forum of an issue with GetGuiObjectAtPosition not detecting a Gui that has Active set to true, maybe that’s what causing the problem to happen?

1 Like

i will look into that thanks for the help

1 Like

ok from what i understood :GetGuiObjectsAtPosition only works for mouse position, so what i instead did is i used a module called “GuiCollisionService” made by @jaipack17

and i did the following script

local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")
local GuiCollisionService = require(game:GetService("ReplicatedStorage").COLLISION_SERVICE.GuiCollisionService)
local GuiService =game:GetService("GuiService")

local DeathGroup = GuiCollisionService.createCollisionGroup()
DeathGroup:addHitter(script.Parent, {  })

local player = DeathGroup:getHitter(1)


local MovingFrame = script.Parent

local Info = TweenInfo.new(.85, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true,0)
local Goal = {Position = UDim2.new(0.969, 0,.5, 0)}

local Tween = TweenService:Create(MovingFrame, Info, Goal)

local function StartMoving()

	Tween:Play()

	local Loop  =Tween.Completed:Connect(function()

		Tween:Play()

	end)
	
	return Loop
	
end

local Loop
local Paused = false

Loop = StartMoving()


for i,v in pairs(script.Parent.Parent:GetChildren()) do

	if v.Name == "CorrectArea" then

		DeathGroup:addCollider(v, false)

	end
end

UserInputService.InputBegan:Connect(function(key)

	if key.UserInputType == Enum.UserInputType.MouseButton1 then
	
		Loop:Disconnect()
		Tween:Pause()
		
		Paused = true
		
		wait(1)
		
		Paused = false
		
		Loop = StartMoving()

	end

end)

player.CollidersTouched.Event:Connect(function(hits)

	for i,v in pairs(hits) do

		if v.Name == "CorrectArea" and Paused == true then

			print('HIT Green Bar')

		end
	end
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.