Thats okay! Nobody is perfect.
The created coroutine is automatically garbage collected when completed, so thread buildup isnāt a problem. Fun fact, scripts in Roblox are actually coroutines themselves.
In addition, loops are calling actions in this case more often. Humanoid is only setting the jump to true when it lands, while the loop does it every wait(0.1)+tick()*2
seconds.
Itās best to have games in Lua, both in-roblox and out, use the least amount of loops with yielding methods. Events are called less and are much more accurate, therefore saving a ton of memory.
However, for creating some connection
events, be weary of manual garbage collection!
@Koala_Helper I opened the script in studio and found my issues. I now use .Changed
instead of .StateChanged
-- // Constants
local Button = script.Parent --// Change this to what u need
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = Character:WaitForChild("Humanoid")
-- // Variables
local IsJumping = false
-- // Functions
local function OnButtonActivated()
IsJumping = not IsJumping
if IsJumping then
humanoid.Jump = true
end
end
-- // Binds
Button.MouseButton1Down:Connect(OnButtonActivated)
humanoid.Changed:Connect(function()
if IsJumping and humanoid.Jump == false then
humanoid.Jump = true
end
end)
It is possible. Thereās a property of the Humanoid called Jump, once set to true the character will automatically jump.
Iāll try thatā¦
Does it work? If not, I can help a bit more
It didnāt work so far. I will keep trying.