I’m making a Tutorial in my game and to show where the player clicks I use a sorta highlight effect with UI so its just a frame that tweens to the position and the size of the target frame, but i’m having an issue where it doesn’t work as intended on all devices, sometimes its exactly offset by the size of the y axis of the UI and on mobile its not even near.
This is the codeblock
local function updateHighlightFrame(uiObject)
if not uiObject then return end
game:GetService("RunService").RenderStepped:Wait()
local absPos = uiObject.AbsolutePosition
local absSize = uiObject.AbsoluteSize
local scrollOffset = Vector2.zero
local scrollingFrame = uiObject:FindFirstAncestorWhichIsA("ScrollingFrame")
if scrollingFrame then
scrollOffset = scrollingFrame.CanvasPosition
end
local correctedPos = absPos - scrollOffset
local centerX = correctedPos.X + absSize.X / 2
local centerY = correctedPos.Y + absSize.Y / 2
local targetPos = UDim2.new(0, centerX, 0, centerY)
local targetSize = UDim2.new(0, absSize.X * 1.2, 0, absSize.Y * 1.2)
TweenService:Create(highlightFrame, TweenInfo.new(0.5, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out), {
Position = targetPos,
Size = targetSize
}):Play()
end
Please let me know if you have a fix!