Currently, I have made a simple script that plays a sound when touching the part.
local sound = game.Workspace["E-11PA"]
local part = script.Parent
local function music(otherPart)
local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
if humanoid then
if not sound.IsPlaying then
sound:Play()
end
end
end
part.Touched:Connect(music)
wait(26)
game.Workspace["E-11PA"]:Destroy()
But instead of playing the sound when everyone touches the part, I want the sound to play only when a specific team touches the part.
What changes should I make in the script to do this?
local sound = game.Workspace["E-11PA"]
local part = script.Parent
function music(otherPart)
local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
if humanoid then
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player.Team == "AddYourTeam" then
if not sound.IsPlaying then
sound:Play()
end
end
end
end
part.Touched:Connect(music)
task.wait(26)
game.Workspace["E-11PA"]:Destroy()
Thank you very much for your help. However, I would like to state that I could not find a real solution to this.
But I believe I have found a solution after spending hours on something simple.
local sound = game.Workspace.Sound
local part = script.Parent
script.Parent.Touched:Connect(function(otherPart)
local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
if humanoid then
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player.TeamColor == BrickColor.new("TEAM COLOR") then
if not sound.IsPlaying then
sound:Play()
wait(Seconds until your sound is over)
game.Workspace.Sound:Destroy()
end
end
end
end)
local sound = workspace["E-11PA"]
local part = script.Parent
function music(otherPart)
local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
if humanoid then
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
if player.Team.Name == "Green" then --instead Green write your Team Name
if not sound.IsPlaying then
sound:Play()
sound.Ended:Wait()
sound:Destroy()
end
end
end
end
part.Touched:Connect(music)