Walkspeed and FloorMaterial

Hello lovely people!

I am trying to set up a different speed when the player is walking on cobblestone, I have the following script and place it on StarterGui without luck. (also tried placing it in other places and even tried it as a server script in ServerScriptService.

	if 	game.Players.LocalPlayer.Character.Humanoid.FloorMaterial == "Cobblestone" then
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 30
		print("cobblestone")
	else
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
	end
end)

I got no errors when running this script. Welp!

Space

1 Like

Have you tried placing it in Starter Character Scripts? After all, the scripts for the character are there. Also, what is that last

end)

doing there?

1 Like

Try using Enum:

if 	game.Players.LocalPlayer.Character.Humanoid.FloorMaterial == Enum.Material.Cobblestone then
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 30
		print("cobblestone")
	else
		game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16
	end

Also, you can’t use LocalPlayer on a server script.

2 Likes

it should be a local script in starter characterscripts

2 Likes

like people have said before me, use Enum.Material .Cobblestone and put it in starter character but i would add a loop to it since the script only checks one time if ur on cobblestone

A Runservice would be better i guess

1 Like

yea, that’s the only loop i use except for loops but that would work in this case

First of all, server scripts cannot access LocalPlayer as it’s a nil value in the Server. You should try putting it has a local script in StarterPlayer> StarterCharacterScripts or StarterPlayerScripts (Depends on the script)

Try threading it in a while loop or RunService. Or another thread thing! it might be checking when the player is spawned, and do not detect it again while you’re running. I hope my explanation makes sense.

Edit: I tried it on my place with while loop in StarterCharacterScript. and it worked!

1 Like

I didn’t understand exactly what you want. Want the player’s speed to change when walking on a part?

1 Like

You dont need to use a loop, its useless and take a lot of ressources for nothing.
Just use humanoid.changed

1 Like

Try Enum.Material.Cobblestone instead of “Cobblestone”

2 Likes

It’s a good practice, yes. But, it still worked.

2 Likes

I wish I could set a few of the answers as solution. BIG thank you for everyone to jump in and help, these is one of those easy solvable issues that was right in front of my eyes, and I hope all of your answers can help others with the same inquire.

You rock! let’s get these devs some hearts!(likes)

2 Likes