Why does my script not detect when im walking in sand?

this is a client sided script located in the workspace, normally it should transform the player’s walkspeed to 10 when he walks on sand but it doesn’t
script:

local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:FindFirstChildOfClass("Humanoid")

hum.PlatformStanding:Connect(function(active)
   if active then
        if Enum.Material.Sand and Enum.HumanoidStateType.Running then
            hum.WalkSpeed = 10
       else
            hum.WalkSpeed = 16
       end
   end
end)
1 Like

thats because platformstand doesn’t detect when you are stepping in something, what it does you can check on here PlatformStanding

1 Like

i did read it but didn’t understand very well cuz i have adhd

1 Like

You can check what material the character is standing on with Humanoid.FloorMaterial.

local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:FindFirstChildOfClass("Humanoid")

hum.PlatformStanding:Connect(function(active)
   if active then
        if hum.FloorMaterial == Enum.Material.Sand and Enum.HumanoidStateType.Running then
            hum.WalkSpeed = 10
       else
            hum.WalkSpeed = 16
       end
   end
end)
1 Like

should be a local script in startercharacterscripts right?

2 Likes

Yes, that should work correctly.

didn’t work no errors btw
11111

1 Like

Sorry, I just checked, and the floor material is always set to Air when platform standing.

If you want the player’s speed to decrease when walking on sand, you can detect whenever the player tries to move, then check if they are on sand.

Try this:

local plr = game.Players.LocalPlayer
local char = plr.Character
local hum = char:FindFirstChildOfClass("Humanoid")

hum:GetPropertyChangedSignal("MoveDirection"):Connect(function() -- Fires when the player tries to walk
	if hum.FloorMaterial == Enum.Material.Sand then -- Check if the player is standing on sand
		hum.WalkSpeed = 10
	else
		hum.WalkSpeed = 16
	end
end)
1 Like

tysm brother :slight_smile:
111111111111111111111111

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