Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Creating a script that makes different sounds for the different materials I step on?

Asked by 5 years ago
Edited 5 years ago

Sorry if this is a long post, but I've been working on this code for the past 4 days and I can't work my way around it no matter what I do. I will only post my last attempt with my script down below for everybody to see, not my 15-20 other tries.

The point of this code to put it simply is to create a script that plays different sounds for the different materials I step on.

In my mind, if I can't figure out this issue to the point where I have to solve another problem like this, there's no way I can be making games like I want to.

My code: https://pastebin.com/DfjGREgb

(i had to post a pastebin link, because my code wouldn't format correctly)

I have tried everything that I can think of, and nothing has worked. I've stayed up until 5AM almost every morning trying to figure this issue out, to no avail. I've asked several people with no help, so here I am.

So, where do I start..

The table you see is setup so that, in the function below it, the values inside the Keys can be used to create all the sounds needed, for the Enumerations I list in the table.

All of the sounds are created, and held inside their appropriate Key. They are then used later on in the script. I do this so I can easily create new sounds, for new materials if need be, just buy editing or adding new Enums.

(the pitch calculation for the script hasn't been added in yet)

The isGroundedFunc() is not being used right now because it needs a recode.

The biggest issue the the last section of the code...

I've had problem with the logic (and some syntax errors, of course), and I can't for the life of me figure out how to setup the last while loop so that it does the required checks. This comes from inexperience mostly.

To break the last while loop down:

I first start off with declaring a variable that gets the material that the player is currently stepping on.

Next I check if the player is actually walking, because if they aren't, it's pointless to play a sound. If they are walking, I then check if the currentSound is equal to the current material that the player is currently stepping on.

After that, I check if the table enumeration is missing, or nil, because it crashes the script if I try and run a sound that isn't present. If it isn't nil, I play the sound that's equal to the variable, touchingMaterial.

--One of the issues I have here is that the sound is played and replayed instantly as I keep walking. If I do stop, the sound does actually stop, like it's supposed to. But, if step on a material that isn't LeafyGrass, or wood in this case, the wood doesn't stop itself.

Looking back at the code to find and fix these issues confuses me... I do eventually find the issue most of the time, but it never fixes it to the point that the script is finished.

Although I do need the code fixed, please give me critisism on how to get better at completing a task like this. I know the script may seem slightly long, but it's because I create all the sounds within the script, and do all of the calculations in different functions, so I can eventually use them for when I play the different sounds.

Thank you for taking the time to help me!

0
You can maybe use the FloorMaterial property in Humanoid. It gives you the material that the character is currently walking on. dadysherwin2 155 — 5y
0
If you took time to look at the code, that' exactly what I did, lol. xXxGODxISxREALxXx 7 — 5y

Answer this question