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.