Invalid argument #3 to 'clamp'

Hey! I’ve been trying to make boundaries for a draggable gui, but I get this error, even though that the max value of the clamp is bigger than the minimal one. Does anyone know what I got wrong?

The code:

local DraggableObject = require(script.Parent.DraggableObject)
local FrameDrag = DraggableObject.new(script.Parent)
local Frame = script.Parent
local CurrentPositionX = Frame.Position.X.Scale
local CurrentPositionY = Frame.Position.Y.Scale
local ClampXMin = -0.074
local ClampXMax = -0.874
local ClampYMin = -0.001
local ClampYMax = -0.584
local ClampX = math.clamp(CurrentPositionX, ClampXMin, ClampXMax)
local ClampY = math.clamp(CurrentPositionY, ClampYMin, ClampYMax)

FrameDrag:Enable()
FrameDrag.DragStarted = function()
	print(ClampX)
	print(CurrentPositionX)
	if ClampX == -0.874 then
		FrameDrag:Disable()
	end
end

Error:

-0.874 is lower than -0.074, change them

1 Like

It’s not lower tho?

characterssssss

they are, thats how negative works

Oh right, I’m dumb lol, my bad.

Yep, that fixed the error, thanks. However the boundaries still don’t work, do you know how I could fix it?

local DraggableObject = require(script.Parent.DraggableObject)
local FrameDrag = DraggableObject.new(script.Parent)
local Frame = script.Parent
local CurrentPositionX = Frame.Position.X.Scale
local CurrentPositionY = Frame.Position.Y.Scale
local ClampXMin = -0.874
local ClampXMax = -0.074
local ClampYMin = -0.584
local ClampYMax = -0.001
local ClampX = math.clamp(CurrentPositionX, ClampXMin, ClampXMax)
local ClampY = math.clamp(CurrentPositionY, ClampYMin, ClampYMax)

FrameDrag:Enable()
FrameDrag.Dragged = function()
	if ClampY == ClampYMin or ClampY == ClampYMax then
		FrameDrag:Disable()
		print("You cannot drag anymore")
	elseif ClampY == CurrentPositionY then
		print("You can drag now")
	end
end

Maybe place local ClampX and local ClampY inside the Dragged function? like this:

FrameDrag.Dragged = function()
	local ClampX = math.clamp(Frame.Position.X.Scale, ClampXMin, ClampXMax)
	local ClampY = math.clamp(Frame.Position.Y.Scale, ClampYMin, ClampYMax)
	if ClampY == ClampYMin or ClampY == ClampYMax then
		FrameDrag:Disable()
		print("You cannot drag anymore")
	elseif ClampY == CurrentPositionY then
		print("You can drag now")
	end
end

it looks like disabling drag would break something too, but i am unsure

1 Like

I tested it and I believe it still doesn’t work, however thanks for trying to help me.

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