Hello, I am trying to make a textLabel which follows the user’s cursor around. The only problem, is that the label is very offset from the cursor.
Here is my code:
local players = game:GetService("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()
local event = script.Parent:WaitForChild("GivePrice")
local priceLabel = script.Parent:WaitForChild("PriceLabel")
event.Event:Connect(function(pass, price, button)
if pass then
priceLabel.Visible = true
priceLabel.Text = "$" .. price
while pass do
priceLabel.Position = UDim2.fromOffset(mouse.X, mouse.Y)
wait()
end
end
if not pass then
priceLabel.Visible = false
priceLabel.Text = "$"..tostring(nil)
end
end)
Here is what happens, as you can see there is insane offset.
I have proposed another solution if you don’t want to reparent it to it’s ancestor ScreenGui.
frame = script.Parent
parentFrame = frame.Parent
mouse = game.Players.LocalPlayer:GetMouse()
function a()
-- also works with non-(0, 0) anchor point
local difference = parentFrame.AbsolutePosition - Vector2.new(mouse.X, mouse.Y)
local wanted_pos = Vector2.zero - difference
local X = wanted_pos.X
local Y = wanted_pos.Y
frame.Position = UDim2.fromOffset(X, Y)
end
game:GetService("RunService").RenderStepped:Connect(a)