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

How do I make it so two different teams have custom footstep sounds?

Asked by 4 years ago

Hey, I was wondering how I would make my game have different footstep sounds for two different teams? (e.g. one team having an electronic sounding footstep and the other a different sounding footstep)

Any help would be appreciated!

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Let's say we had two teams: purple team and red team. Inside a local script, we could check what the player's team is and change their footstep audio based on that.

local Teams = game:GetService("Teams")
local Players = game:GetService("Players").LocalPlayer

local footstepsAudioObject = script.Parent.Head:WaitForChild("Running") --the audio for the 

--the footstep audio for each team
 --this is where the audio asset id goes 
local PurpleFootsteps = "put audio id here"
local RedFootsteps = "assetid goes here"

--change the footstep audio based on which team the player is on
if (player.Team == Teams.Purple) then
    footstepsAudioObject .Id = PurpleFootsteps
elseif(player.Team == Teams.Red)then
    footstepsAudioObject .Id = RedFootsteps
end

Doing the above script works, but what if we want a bunch of teams? 100 teams? We're too lazy and we don't want to do that. Instead, we can keep a dictionary of teams and their asset ids:

the table would look like this: the following code below assumes we have teams for each color in the rainbow:

teamFootstepSounds = {
    [Teams.Red]  = "your asset id goes here",
    [Teams.Orange] = "your asset id goes here",
    [Teams.Yellow] = "your asset id goes here",
    [Teams.Green] = "your asset id goes here",
    [Teams.Blue] = "your asset id goes here",
    [Teams.Violet] = "your asset id goes here",
}

then we can loop through our dictionary checking if the player's team is the team we're currently looking at:

for team, soundId in pairs(teamFootstepSounds)do
    if (player.Team == team) then
        footstepsAudioObject.Id = soundId
end
Ad

Answer this question