Issues binding and unbinding action based on floor material

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?

2 Likes

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)

You sure you didn’t mean elseif here.

Is there a difference between the two? Also the above solution doesn’t work, sorry

I think you may have meant to do CAS:UnbindAction(Trick) instead of CAS:UnbindAction(“Trick”).

1 Like

I am a complete idiot who should never be allowed to cook again. This fixed it… scripting is a mystery to me LOL

1 Like

I make mistakes like this all the time, don’t be hard on yourself bro.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.