Problem with 2d platformer physics

Okay, so, I’m working on a platformer reminiscent of the classic 1980 platformers that only uses the gui roblox provides for the level and objects. I have scripted a object, collision, and gravity so far, but when I started adding a jump mechanic, the physics break. The player/object glitches out and moves slightly into the ground (I believe the object teleports a bit upwards then opposite of that), and I am unsure how to fix this. There’s not really any info I could find about this specific problem, so I’m here looking for help now.


local RS = game:GetService("RunService")

local uis = game:GetService("UserInputService")

local pg = game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')

local object = pg.levels.Level.object

local frame = pg.levels.Level.Frame

local xoffset = object.Position.X.Offset

local yoffset = object.Position.Y.Offset

local t = 0

	if i.KeyCode == Enum.KeyCode.Space then
		object.jumping.Value = true


		local y = object.Position.Y.Scale
		local x = object.Position.X.Scale
	    local g = 0.01

		local a1 = object.AbsolutePosition.Y
		local b1 = frame.AbsolutePosition.Y
		local a2 = a1 + object.AbsoluteSize.Y
		local b2 = b1 + frame.AbsoluteSize.Y

	if object.jumping.Value == false and (b1 <= a1 and b2 <= a1) or (a2 <= b1 and a2 <= b2) then
			t = t + 0.07
			object.Position =, xoffset, y+g*t^2 / 2, yoffset)


	if object.jumping.Value == true then
		t = t + 0.07
		object.Position =, xoffset, y-g*t^2 / 2, yoffset)
		if y >= -0.500 then
object.jumping.Value = false