A few weeks ago I had written a script that increases/decreases the players walkspeed depending on the terrain/material the player is currently standing on. Fast forward to now, for some reason it fails to work when a player enters a new material.
The current code looks like this:
--// idk why this stopped working
local players = game:GetService("Players")
--// Table for all the materials and their speed
--// Their value is how much their speed decreases, NOT their walkspeed value
--// If you want the speed to increase, make the value a negative
local materials = {
[Enum.Material.Asphalt] = 0,
[Enum.Material.Basalt] = 0,
[Enum.Material.Brick] = 0,
[Enum.Material.Cobblestone] = -2.6,
[Enum.Material.Concrete] = 0,
[Enum.Material.CrackedLava] = 0,
[Enum.Material.Glacier] = 0,
[Enum.Material.Grass] = 1,
[Enum.Material.Ground] = 2.4,
[Enum.Material.Ice] = 0,
[Enum.Material.LeafyGrass] = 1,
[Enum.Material.Limestone] = 0,
[Enum.Material.Mud] = 4.2,
[Enum.Material.Pavement] = -2,
[Enum.Material.Rock] = 4,
[Enum.Material.Salt] = 0,
[Enum.Material.Sand] = 3,
[Enum.Material.Sandstone] = 0,
[Enum.Material.Slate] = 3,
[Enum.Material.Snow] = 6,
[Enum.Material.Wood] = 0,
}
players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
--// Detects when a players floormaterial changes
humanoid.Died:Connect(function()
return print("player died, ending thread.")
end)
humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
print("new material detected")
-- the argument we pass is a string with the name of the property
for i,v in pairs(materials) do
if humanoid.FloorMaterial == i then
humanoid.WalkSpeed = 16 - v
print(humanoid.WalkSpeed)
end
end
end)
end)
end)
I have a feeling it may be an issue with humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
due to the fact I had written down a print statement that should run every time the player enters a new material, however it does not run at all.
If someone could tell me if this is something im doing wrong on my end or if its an issue with GetPropertyChangedSignal, that would be much appreciated.