Changing players walkspeed depending on the material they're standing on?

I’m making a racing game, but I don’t know what the most efficient method of changing the players walkspeed would be when they’re standing on different materials.

For Example:

16 on Plastic
25 on Ice
Etc

Any help is appreciated!

Heyo!

You can try to use a humanoid property called FloorMaterial and make a script that logs the current floor material to check what the player is running on.

image

Example

humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
	if humanoid.FloorMaterial == Enum.Material.Plastic then
		humanoid.WalkSpeed = 16
	elseif humanoid.FloorMaterial == Enum.Material.Marble then
		humanoid.WalkSpeed = 32
	end
end
  • Edited because I forgot to list the Enum.Material part.
1 Like

I’m not sure if I did anything wrong or if i’m missing something but this wouldn’t work

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

humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
	if humanoid.FloorMaterial == "Plastic" then
		humanoid.WalkSpeed = 16
	elseif humanoid.FloorMaterial == "Ice" then
		humanoid.WalkSpeed = 32
	end
end)

What script is this in? is it a local script and is it in StarterCharacterScripts?

Do you have the materials listed in your code on the ground?

Also check what the humanoid floor material property is in the property tab so that you can make sure it actually comes up.

OK WAIT

@Marioplays9484

ok so my dumbass forgot to list Enum.Material.Ice

Here, try this!

humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
	if humanoid.FloorMaterial == Enum.Material.Ice then
		humanoid.WalkSpeed = 32
	elseif humanoid.FloorMaterial == Enum.Material.Plastic then
		humanoid.WalkSpeed = 16
	end
end)
1 Like

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