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.
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)
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