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

How would you detect if a player has jumped?

Asked by 3 years ago

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.

0
script.Parent.Humanoid.Changed:Connect(function() if script.Parent.Humanoid.Jump == true then (code here) end end) Brycefitz2008 2 — 3y

2 answers

Log in to vote
0
Answered by
174gb 290 Moderation Voter
3 years ago
Edited 3 years ago

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)
0
Thanks! I can probably modify this to fit my game a bit better but this is great ExoRay09 2 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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
0
Should fix; if not idk. PufferfishDev 49 — 3y
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 ExoRay09 2 — 3y

Answer this question