Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

UDim2 is not a valid member of TextLabel? (LINE 9)

Asked by 9 years ago

I made a script where when you have your mouse on a certain part and it shows a GUI that follows your mouse, but it won't work. Can somebody help me with it?

local Plyr = game.Players.LocalPlayer
local Mouse = Plyr:GetMouse()
local Object = game.Workspace.Interact1
while true do
    if Mouse.Target == Object then
        script.Parent.MouseGUI.TextLabel.UDim2 = UDim2.new(Mouse.UDim2)
        elseif Mouse.Target ~= Object then
    wait(0.0000000000000000000001)
    script.Parent.MouseGUI.TextLabel.UDim2 = UDim2.new(0,-500,0,0)
    end
    wait()
end
0
UDim2 is not a property of GUIs. It is used to define the size or position of a GUI. You'd put .Position or .Size in it's place. FearMeIAmLag 1161 — 9y

2 answers

Log in to vote
2
Answered by
dyler3 1510 Moderation Voter
9 years ago

UDim2 is not used directly on the gui. It's used as a Data type to store the Size and Position of the gui. Something like this would work:

local Plyr = game.Players.LocalPlayer
local Mouse = Plyr:GetMouse()
local Object = game.Workspace.Interact1
while true do
    if Mouse.Target == Object then
        script.Parent.MouseGUI.TextLabel.Position = UDim2.new(0,Mouse.X,0,Mouse.Y) --Mouse.UDim2 doesn't exist. Change to Mouse.X, and Mouse.Y to get where the Offsets of where the mouse is at.
    elseif Mouse.Target ~= Object then
        wait() --This is the smallest wait time you can do, which defaults to 1/32 of a second.
    script.Parent.MouseGUI.TextLabel.Position= UDim2.new(0,-500,0,0)
    end
wait()
end

(Make sure this is in a LocalScript. If it's not, you can't use LocalPlayer)

Anyways, the script should hopefully work how you planned now. If you have any questions or problems, please leave a comment below. Hope I helped :P

Ad
Log in to vote
1
Answered by 9 years ago

You're referencing it's position incorrectly. UDim2 is the format the pixels are sized/positioned in, not the size/position itself. So the correct way to do this is:

script.Parent.MouseGUI.TextLabel.Position = UDim2.new(0,-500,0,0)

Answer this question