Help with GUI Character jump?

I’m trying to make a 2D game only with guis but I struggle to make it jump. When I make it jump, it jumps instantly, and I don’t know why and what did I do wrong, and I even added a wait().

Video Problem: https://gyazo.com/1cca26a08c51ecff8dabc949b97cdead

Code (Place this in a guiobject for helping purposes)
local rs = game:GetService("RunService")
local uis = game:GetService("UserInputService")

function setPosFromJumpPower(power)
	return .0001 * power
end

local waittildoneJump = false
local jumppower = 30

uis.InputBegan:Connect(function(key,gmp)
	if gmp then return end 
	
	if key.KeyCode == Enum.KeyCode.W or key.KeyCode == Enum.KeyCode.Space then
		jumping = true
	end
end)

uis.InputEnded:Connect(function(key,gmp)
	if gmp then return end 
	
	if key.KeyCode == Enum.KeyCode.W or key.KeyCode == Enum.KeyCode.Space then
		jumping = false
	end
end)

rs.RenderStepped:Connect(function()
	
	if jumping and not waittildoneJump then
		waittildoneJump = true -- prevents it from looping
		local pos = script.Parent.Position

		local endJumpPos = setPosFromJumpPower(jumppower)

		for i = .0001,endJumpPos,.0001 do -- PROBLEM IN THIS LINE
			local currentYpos = script.Parent.Position.Y.Scale
			
			script.Parent.Position -= UDim2.new(0,0,currentYpos+i,0)
			wait()
		end

		waittildoneJump = false 
		jumping = false
	end		
end)

function setPosFromJumpPower(power): What this does is that this function gets the position that multiplies with the jumppower in order for it to jump.

1 Like

I have done a similar thing but I used the suvat equations to create a relatively accurate physics sim. There are tonnes of vids and articles on how to use them and I think it would be more beneficial to use suvat in the long run.

Try tweening the gui’s position instead of doing it in a for loop.

Only problem is I don’t know how to do it.

GUIObject:TweenPosition()

1 Like