Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can someone help me for a script that allows to wait for the player to touch the ground?

Asked by 1 year ago

Hey! I'm currently stuck in the programming of my game because of a script that I have to make: the goal is that when I click on the button I created, the character starts to jump and I have to wait for it to hit the ground before I can click again. I have already managed to program the script to make the character jump but I can't manage to do the one that allows me to wait for the character to touch the ground before being able to click again. Here is the script:

-- Parameters
local WAIT_TIME = .5

-- Services
Player = game:GetService("Players")

local button = script.Parent
local canActivate = true

local function playerJump()
    if canActivate then
        canActivate = false
        local localPlayer = Player.LocalPlayer
        local character = localPlayer.Character
        local Humanoid = character:WaitForChild("Humanoid")

        local oldJumpPower = Humanoid.JumpPower
        Humanoid.JumpPower = 1
        Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
        Humanoid.JumpPower = oldJumpPower

        task.wait(WAIT_TIME)
        canActivate = true
    end
end

button.Activated:Connect(playerJump)

I hope that someone could help me! Thanks in advance! Belox.

0
Maybe 0.5 seconds is a bit short of time to notice if the debounce works or not, try to make it into a bigger wait number, like 5, to make sure the debounce works fine Borrahh 265 — 1y
0
My script allows that, each time I click on the jump button, the jump strength increases by 1, which means that if I put 5 for example, after a while the button will not work because I would be in the air. wDaerkfeX 37 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

Hi,

Heres a script that checks whether the player is touching the floor or is in the air by identifying the floor material found in the humanoid of the player

-- by sne_123456

wait(5)

while true do
    for i,v in pairs(game.Workspace:GetChildren()) do
        if v:IsA("Model") then
            local h = v:FindFirstChildWhichIsA("Humanoid") 
            if h ~= nil then -- finds player
                print("found humanoid")
                if h.FloorMaterial ~= Enum.Material.Air then -- checks if hes in air or not
                    print("Hes not jumping")
                else
                    print("He jumped")
                end
            end
        end
    end
    wait()
end

I tested it so dont tell me it doesnt work

also prepare to get your ooutput filled with thousands of prints xd

0
Thanks a lot! wDaerkfeX 37 — 1y
0
np bro gl sne_123456 439 — 1y
Ad

Answer this question