FloorMaterial Listener not firing

Yes, I did

bad30characterlimit

Try this

local Players = game:GetService("Players")

local function playerAdded(player)
	player.CharacterAdded:Connect(function(character)
		character.Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
			print("FloorMaterial changed to", character.Humanoid.FloorMaterial)
			setValidActions(player)
		end)
	end)
end

for _, player in Players:GetPlayers() do
	playerAdded(player)
end

Players.PlayerAdded:Connect(playerAdded)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid: Humanoid? = character:WaitForChild("Humanoid")

humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
	print("FloorMaterial changed to", humanoid.FloorMaterial)
end)

try running it outside the playeradded/characteradded functions, this worked for me
image

Reread it, and forgot to wait for the humanoid :man_facepalming: Try below

local Players = game:GetService("Players")

local function _characterAdded(player : Player, character : Model)
	local humanoid = character:WaitForChild("Humanoid")
	humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
		print("FloorMaterial changed to", humanoid.FloorMaterial)
		setValidActions(player)
	end)
end

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		_characterAdded(player, character)
	end)

	if player.Character then
		_characterAdded(player, player.Character)
	end
end)
1 Like

I know it works in local scripts (sorry for not making it clear enough in my post), however I need this to be server-sided for some validation things

1 Like

I tried however no success either.

However, I found this post from 2 years ago from someone who had a similar problem. It turned out to be an engine bug, but Roblox staff said it should be fixed…

in case you’re not afraid of using Heartbeat, you can use this maybe:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid: Humanoid? = character:WaitForChild("Humanoid")
		local lastFloorMaterial = humanoid.FloorMaterial
		game:GetService("RunService").Heartbeat:Connect(function()
			local currentFloorMaterial = humanoid.FloorMaterial
			if currentFloorMaterial ~= lastFloorMaterial then
				print("FloorMaterial changed to", currentFloorMaterial)
				lastFloorMaterial = currentFloorMaterial
			end
		end)
	end)
end)
1 Like

LOL

I tried your updated code, it doesn’t seem to work, though.

Is the issue still that it only works the first time the player spawns into the game? And if they reset, it stops working?

once it’s inside a function, you need the function to fire again for the material to change on the server, or at least that’s what I’m assuming from my own tests

1 Like

This works, I will use this as a workaround for now, thanks! :smiley:

1 Like

I’m confused because it looks like it’s working in the video you put. Is the setValidActions function the problem?

it says [client], their script has issues on [server]

1 Like

Exactly! It only works once when the player joins. The player doesn’t even have to reset for it to stop working (As demonstrated in the video).

2 Likes

Actually, in the video, you can see the output of both the LocalScript and the ServerScript. At first the serverScript prints that the material has changed, the following lines in the output were produced only by the local script (note the [SERVER] and [CLIENT] prefixes.)

try this as a hacky workaround until roblox fixes the bug

local Players = game:GetService("Players")

local function playerAdded(player)
	player.CharacterAdded:Connect(function(character)
		local previousMaterial
		character.Humanoid.Changed:Connect(function()
			local newMaterial = character.Humanoid.FloorMaterial
			
			if newMaterial ~= previousMaterial then
				print("FloorMaterial changed to", character.Humanoid.FloorMaterial)
				previousMaterial = newMaterial
			end
		end)
	end)
end

for _, player in Players:GetPlayers() do
	playerAdded(player)
end

Players.PlayerAdded:Connect(playerAdded)
2 Likes

oK did some investigating and it’s a roblox bug. Couldn’t reproduce it in studio but remembered reading something about it in the latest release notes. Fix is pending

Release notes for last week vvv

2 Likes

Tested this and it works

1 Like

Thank you! I will use for now. :happy1:

1 Like