I’m making a function that allows the player to do some acrobatic tricks on the ground. However, as you can guess, I want the player to not be able to do said tricks if they’re in the air. The method I’ve tried to do this with is getting the player’s floor material in a loop and binding and unbinding their tricking action based on that floor material—if it’s not Air, then bind it, if it is, then unbind it. I then connect this loop to RunService.Heartbeat. However, it doesn’t unbind the action when I do a trick in the air.
RUS.Heartbeat:Connect(function()
for Trick, Info in GroundTricks do
if not Info.Keybind then continue end
if Humanoid.FloorMaterial ~= Enum.Material.Air then
CAS:BindAction(Trick, doGroundTrick, true, Info.Keybind)
else if Humanoid.FloorMaterial == Enum.Material.Air then
CAS:UnbindAction("Trick")
end
end
end
end)
I’ve also tried wrapping the function in a while loop instead of tying it to the game’s frames, but that doesn’t work either. Should I be using a different method to check if the character is in the air?
With no loop … client local script.
Untested snippet. Add to what you have.
local rs = game:GetService("RunService")
Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
rs.Stepped:Wait()
if Humanoid.FloorMaterial == Enum.Material.Limestone then
CAS:BindAction(Trick, doGroundTrick, true, Info.Keybind)
elseif Humanoid.FloorMaterial == Enum.Material.Air then
CAS:UnbindAction("Trick")
end
end)