Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

1 comment

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.

2 answers

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.