Invalid argument #1 (Vector2 expected, got number)

Don’t know why vector2 was expected or what that means but I need help with my script.

Error code:

Players.militry22q.PlayerGui.RGBColorPicker.Base.SliderGui.RedBar.SliderHandler:24: invalid argument #1 (Vector2 expected, got number)

My Code:

local UIS = game:GetService("UserInputService")

local sliderFrame = script.Parent
local sliderButton = sliderFrame.Slider
local sliderDisplay = sliderFrame.SliderValue
local sliderDragging = false

sliderButton.MouseButton1Down:Connect(function()
	sliderDragging = true
end)

UIS.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		sliderDragging = false
	end
end)

UIS.InputChanged:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		if sliderDragging == true then
			local mouseLoc = UIS:GetMouseLocation()
			local abs_size = sliderFrame.AbsoluteSize
			local abs_pos = sliderFrame.AbsolutePosition
			local max = abs_pos.X + (abs_size * .5)
			local min = abs_pos.X - (abs_size * .5)
			local percentage = math.clamp((max - mouseLoc.X)/(max - min), 0, 1)
			sliderButton.Position = UDim2.new(percentage,0,0.5,0)
            sliderDisplay.Text = ("%.0f"):format(sliderButton.Position * 255)
		end
	end
end)

Please help me. Thank you

AbsoluteSize is a Vector2 Value, so it thinks that you are trying to add a vector 2 to your abs_size variable. What you do though is number ± (Vector2 * 0.5) when it probably should be number + number * 0.5.

abs_size also needs to have a .X or .Y

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.