Cannot position UI by mouse cursor

Code:

local ShapeInfo = script.Parent:WaitForChild("ShapeInfo")

local TopHolder = script.Parent:WaitForChild("TopHolder")

local StatusDisplay = TopHolder:WaitForChild("Status")

local ShapeCapacityHolder = script.Parent:WaitForChild("ShapeCapacityHolder")

local Bar = ShapeCapacityHolder:WaitForChild("Bar")

local CapacityIndicator = ShapeCapacityHolder:WaitForChild("CapacityIndicator")

local TimeLeftDisplay = TopHolder:WaitForChild("TimeLeft")

local SpawnRateDisplay = script.Parent:WaitForChild("SpawnRate")

local GameInfo = game:GetService("ReplicatedStorage"):WaitForChild("GameInfo")

local Status = GameInfo:WaitForChild("Status")

local TimeLeft = GameInfo:WaitForChild("TimeLeft")

local GameStarted = GameInfo:WaitForChild("Started")

local ShapeStorageCapacity = GameInfo:WaitForChild("ShapeStorageCapacity")

local ShapeStorage = workspace:WaitForChild("ShapeStorage")

Status:GetPropertyChangedSignal("Value"):Connect(function()
	
	StatusDisplay.Text = Status.Value
	
end)

TimeLeft:GetPropertyChangedSignal("Value"):Connect(function()
	
	local mins = math.floor(TimeLeft.Value / 60)
	
	local secs = TimeLeft.Value % 60

	-- Formatting minutes and seconds together using string.format
	
	TimeLeftDisplay.Text = string.format("%d:%02d", mins, secs)
	
	if TimeLeft.Value == 0 then
		
		task.wait(1)
		
		TimeLeftDisplay.Text = ""
		
		ShapeInfo.Text = ""
		
	end

end)

GameStarted:GetPropertyChangedSignal("Value"):Connect(function()
	
	if GameStarted.Value == true then
		
		ShapeInfo.Text = "🔺 0% (0) | 🟥 0% (0) | 🔴 0% (0) | ♦ 0% (0)"
		
		ShapeInfo.Visible = true
		
	end
	
end)

local TS = game:GetService("TweenService")

local UIS = game:GetService("UserInputService")

local plr = game.Players.LocalPlayer

ShapeStorage.ChildAdded:Connect(function()
	
	local TotalShapes = ShapeStorage:GetChildren()
	
	local Pyramids = 0
	
	local Squares = 0
	
	local Balls = 0
	
	local Diamonds = 0
	
	for _, Shape in pairs(ShapeStorage:GetChildren()) do
		
		if Shape.Name == "Triangle" then
			
			Pyramids += 1
			
		elseif Shape.Name == "Square" then

			Squares += 1
			
		elseif Shape.Name == "Ball" then

			Balls += 1
			
		elseif Shape.Name == "Diamond" then

			Diamonds += 1
			
		end
		
	end
	
	CapacityIndicator.Text = #ShapeStorage:GetChildren() .. "/" .. ShapeStorageCapacity.Value .. " (" .. math.floor((#ShapeStorage:GetChildren() / ShapeStorageCapacity.Value) * 100) .. "%)"
	
	TS:Create(Bar,TweenInfo.new(0.1,Enum.EasingStyle.Sine,Enum.EasingDirection.InOut),{Size = UDim2.new(#ShapeStorage:GetChildren() / ShapeStorageCapacity.Value,0,1,0)}):Play()
	
	local decimalPlaces = 1
	
	local PyramidPercent = math.floor((Pyramids / #ShapeStorage:GetChildren()) * 10^decimalPlaces + 0.5) / 10^decimalPlaces
	
	local SquarePercent = math.floor((Squares / #ShapeStorage:GetChildren()) * 10^decimalPlaces + 0.5) / 10^decimalPlaces
	
	local BallPercent = math.floor((Balls / #ShapeStorage:GetChildren()) * 10^decimalPlaces + 0.5) / 10^decimalPlaces

	local DiamondPercent = math.floor((Diamonds / #ShapeStorage:GetChildren()) * 10^decimalPlaces + 0.5) / 10^decimalPlaces
	
	ShapeInfo.Text = "🔺 " .. tostring(PyramidPercent) .. "% (" .. tostring(Pyramids) .. ")" .. " | " .. "🟥 " .. tostring(SquarePercent) .. "% (" .. tostring(Squares) .. ")" .. " | " .. "🔴 " .. tostring(BallPercent) .. "% (" .. tostring(Balls) .. ")" .. " | " .. "♦ " .. tostring(DiamondPercent) .. "% (" .. tostring(Diamonds) .. ")"
	
	SpawnRateDisplay.Text = tostring(1 / 0.25) .. " " .. plr.AssignedShape.Value .. "s/s"
	
	SpawnRateDisplay.Position = UDim2.new(UIS:GetMouseLocation().X,0,UIS:GetMouseLocation().Y,0)
	
end)

Pretty much i want the textlabel to be offsetted to the right a little by the mouse cursor. The problem is when i look at the position it is set to something like 1000 instead on x and 500 on y

Main:

SpawnRateDisplay.Position = UDim2.new(UIS:GetMouseLocation().X,0,UIS:GetMouseLocation().Y,0)

You are setting the scale to be the mouse coordinate, not the offset.

UDim2.new(0, UIS:GetMouseLocation().X,0,UIS:GetMouseLocation().Y)
1 Like