GetPropertyChangedSignal only runs twice

  1. What do you want to achieve?
    For the GetPropertyChangedSignal to run everytime, not just twice and then that’s it.

  2. What is the issue?
    It seems to only run twice. I don’t know how and the script doesn’t get disabled or something.
    image

  3. What solutions have you tried so far?
    I can get the script to run normal in studio but when ran in the ROBLOX player it only runs twice. There’s no documentation on how this happens.

local PlayersService = game:GetService("Players")
PlayersService.PlayerAdded:Connect(function(player)
	warn(player)
	player.CharacterAdded:Connect(function(character)
		warn(character)
		local Humanoid = character:WaitForChild("Humanoid")
		local BoostedBy = nil
		local BoostAmount = 0
		Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
			warn(Humanoid.FloorMaterial)
			if Humanoid.FloorMaterial == Enum.Material.Cobblestone and BoostedBy ~= Humanoid.FloorMaterial then
				BoostedBy = Enum.Material.Cobblestone
				Humanoid.WalkSpeed -= BoostAmount
				BoostAmount = 5
				Humanoid.WalkSpeed += BoostAmount
			elseif Humanoid.FloorMaterial == Enum.Material.Ground and BoostedBy ~= Humanoid.FloorMaterial then
				BoostedBy = Enum.Material.Ground
				Humanoid.WalkSpeed -= BoostAmount
				BoostAmount = -Humanoid.WalkSpeed + 5
				Humanoid.WalkSpeed = 5
			else
				Humanoid.WalkSpeed -= BoostAmount
				BoostAmount = 0
				BoostedBy = nil
			end
		end)
	end)
end)

1 Like

Its simple, GetPropertyChangedSignal can only run when the given property is changed.

That’s the thing. The property is changing. Humanoid.FloorMaterial is constantly changed to the material under the player, and if you use a while loop, you can get the same result except it actually works.
Using a while loop, You can prove it changes and that the function isn’t firing.
image

Try to switch from GetPropertyChangedSignal to Changed, they are the same thing.

Now you can’t tell if the FloorMaterial changed, because it never has that as the parameter.

local PlayersService = game:GetService("Players")

PlayersService.PlayerAdded:Connect(function(player)
	warn(player)
	player.CharacterAdded:Connect(function(character)
		warn(character)
		local Humanoid = character:WaitForChild("Humanoid")
		local BoostedBy = nil
		local BoostAmount = 0
		local db = false
		Humanoid.Changed:Connect(function(property)
			if  tostring(property) ~= "FloorMaterial" then return end
			warn(Humanoid.FloorMaterial)
			if Humanoid.FloorMaterial == Enum.Material.Cobblestone and BoostedBy ~= Humanoid.FloorMaterial then
				BoostedBy = Enum.Material.Cobblestone
				Humanoid.WalkSpeed -= BoostAmount
				BoostAmount = 5
				Humanoid.WalkSpeed += BoostAmount
			elseif Humanoid.FloorMaterial == Enum.Material.Ground and BoostedBy ~= Humanoid.FloorMaterial then
				BoostedBy = Enum.Material.Ground
				Humanoid.WalkSpeed -= BoostAmount
				BoostAmount = -Humanoid.WalkSpeed + 5
				Humanoid.WalkSpeed = 5
			else
				Humanoid.WalkSpeed -= BoostAmount
				BoostAmount = 0
				BoostedBy = nil
			end
		end)
	end)
end)

They aren’t the same thing and you shouldn’t use Changed in practice, but it’s fine for testing.

1 Like

I know and I was trying it out because they said so, it still seems even roblox code examples don’t work. Is the event bugged or something?

Can you show a video, also you do not need to add a tostring().

Your original script works perfectly for me

code to generate materials for testing if you want it
local model = Instance.new("Model")
model.Name = "Materials"
model.Parent = game.Workspace
for index, material in Enum.Material:GetEnumItems() do
    local part = Instance.new("Part")
    part.Material = material
    part.Size = Vector3.new(6,.5,6)
    part.Anchored = true
    local x = (index-1) % 6
    local y = math.floor((index-1) / 6)
    part.CFrame = CFrame.new(x*6, 10, y*6)
    part.Parent = model
end

Where is your script located? What materials are you walking on? Is anything else in the environment changing? Does your script work in other games or on an empty baseplate?

ServerScriptService

Cobblestone, Grass and Ground, All terrain (not parts)

No

Also no (No output at all)

You might need to use raycasting to get the material of terrain. Have you tried that yet?

I believe this is a bug, I posted about this here, didn’t realize this was getting at the same thing until now: FloorMaterial Changed Event Not Firing Outside of Studio

Do you have a script inside the PlayerGui called LocalPlayer removing parts? If you do, that’s the problem.