Help with checking a value/property constantly

So what I need to achieve is to have a piece of code, that checks if a property of Humanoid remained the same for, let’s say 5 seconds. I can’t just check it before and after, since I’m using Humanoid.FloorMaterial, and it wouldn’t work as intended, since it checks if there is Enum.Material.Air beneath the player. So if they jumped at the start and at the end, it wouldn’t work. So how would I go achieving this? Or how could I constantly check during the 5 given seconds?

During the 5 second generate a ray which updates its tail (starting point of ray) and points down on the upvector checking if it is colliding with the FloorMaterial you want.

That’s kind of redundant, since I can check the Humanoid.FloorMaterial property, which basically already achieves this.

Please post the code of what you’ve already tried. Not sure what you’re having trouble with.
I would just say that “checks if a property of Humanoid remained the same for, let’s say 5 seconds”
can be thought of as “checks if a property of Humanoid has not changed for, let’s say 5 seconds”

I can’t post code because I don’t know where to start. And the two things you said mean exactly the same thing, so I don’t see the issue there.
I’m having trouble detecting when the property Humanoid.FloorMaterial stays the same for 5 seconds. But I can’t just check before and after, since I’m detecting Enum.Material.Air. So if the player were to jump before and after, the function would continue, which I wouldn’t want it to do.

Try this, haven’t tested it yet though

local ChangeCount = 0

Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
ChangeCount+=1
local SavedCount = ChangeCount
if Humanoid.FloorMaterial==Enum.Material.Air then
wait(5)

if ChangedCount==SavedCount then
--Your code here
end

end
end)

That still doesn’t get what I want to achieve. It doesn’t check during the 5 second period. It checks after the 5 seconds have passed. Plus, in your code, SavedCount and ChangeCount+, have not been defined prior to their use.

Could you say what you are using this for to make it easier to help?

Not sure what else to try, sorry

I don’t think it would really make it easier, but I’m trying to achieve an anti-flying exploit script.

Edit: Although I would use this functionality in other scripts too.

Is this what you want?

local Players = game:GetService("Players")

local localPlayer = Players.LocalPlayer or Players:GetPropertyChangedSignal("LocalPlayer"):Wait()
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local start = tick()

humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
	print("CHANGED BEFORE 5 SECONDS")
	
	if tick() - start >= 5 then
		--[[
		only prints when they've
		been on the previous floor
		material 5 seconds or longer
		]]
		
		print("CHANGED AFTER 5 SECONDS")
	end
	
	start = tick()
end)
1 Like

When there is a change you can note the FloorMaterial. Then you can have a different thread have
a loop that checks the start time difference from tick() and fire an event if the previously noted
FloorMaterial was air. You can have this thread loop have a wait(2) or similar so it’s not a cpu hog.