Attempt to perform arithmetic (sub) on nil and number (ui position)

I’m attempting to make a click effect in which will start a transition on the circle, but it doesn’t seem to work as intended when I’m trying to position it, giving me an error (attempt to perform arithmetic (sub) on nil and number). What’s the issue here?

local function createCircle(par, axisX, axisY)
	local clone = script.Circle:Clone()
	clone.Parent = par
	local pos = UDim2.new(0, axisX - par.AbsolutePosition.X, 0, axisY - par.AbsolutePosition.Y - 36) -- error
	clone.Position = pos
	local tween = ts:Create(clone, TweenInfo.new(1, Enum.EasingDirection.Quart, Enum.EasingDirection.Out, 0, false, 0), {Size = UDim2.new(500, 500), ImageTransparency = 0})
	coroutine.wrap(function()
		tween.Completed:Wait()
		clone:Destroy()
	end)()
end
shop.Click.MouseButton1Click:Connect(function(x, y)
	createCircle(shop.Icon, x, y)
end)

x and y are not returns of MouseButton1Click. Consider defining them:

createCircle(shop.Icon, shop.x, shop.y)

I’m attempting to get the mouse’s position, not the shop’s.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local position = Vector2.new(mouse.X, mouse.Y)

This will give you your mouse’s position. To use it in your case:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

shop.Click.MouseButton1Click:Connect(function()
    createCircle(shop.Icon, mouse.X, mouse.Y)
end)
1 Like