Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

2 comments

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

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.

1 answer

✓ Accepted answer

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

2 comments

0

Thanks a lot!

0

np bro gl

This discussion is preserved as it was. New answers, comments, and votes are closed.