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

How would you detect if a player has jumped?

Hello! I'm trying to make a sonic game and I'm a bit stuck on making a ball appear when a character is jumping, I remember reading on the Dev Forum about how the humanoid has a property that detects what material the player is standing on, using this I tried to code a script that makes a ball appear when the character is in the air.

My script:

local Ball = script.Parent.Ball

if script.Parent.Humanoid.FloorMaterial == nil then
	Ball.Transparency = 0
else
	Ball.Transparency = 1
end

The script is a local script in StarterCharacter scripts and the ball wont apear (I have welded it to the Humanoid Root Part) and there are no errors in my output.

I have used a keybind to make it appear when you press space, however I find that this isn't what I was looking for because spamming space in the air would cause the ball to flash despite already being in the air.

1 comment

0

script.Parent.Humanoid.Changed:Connect(function() if script.Parent.Humanoid.Jump == true then (code here) end end)

2 answers

✓ Accepted answer

So you want like this ? Example GIF

I made it on client.. you can make on server too, but you will need to make some adjustments

Here's the place: Place

Here's the code from client side version (Create a local script in 'StarterCharacterScripts' and put ball part on workspace)

local Ball = workspace.Ball
local character = script.Parent
local Humanoid = character:WaitForChild('Humanoid')
Humanoid.JumpPower = 95 -- optional
local Connection


Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
	if Humanoid.FloorMaterial == Enum.Material.Air then
		Connection = game:GetService("RunService").RenderStepped:Connect(function()
			Ball.Transparency = 0.5
			Ball.CFrame = character.HumanoidRootPart.CFrame
		end)
	else
		if Connection ~= nil then
			Connection:Disconnect()
			Ball.Transparency = 1
		end
	end
end)

1 comment

0

Thanks! I can probably modify this to fit my game a bit better but this is great

You are correct with your script, except for one aspect: Instead of nil, it needs to be air.

local Ball = script.Parent.Ball

if script.Parent.Humanoid.FloorMaterial == air then
	Ball.Transparency = 0
else
	Ball.Transparency = 1
end

2 comments

0

Should fix; if not idk.

0

Sorry, air wont work in this, it's an un-known global or something. I can link you the page where this question is asked and theres a great response by Inc_X https://devforum.roblox.com/t/how-does-robloxs-humanoid-detect-if-you-are-grounded/721292

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