✓ Accepted answer
Hey there!
I would start by inserting a 'Sound' into part of the killer's character. In this instance, I am going to insert it into the head. That can be done with a simple line of code:
local sound = Instance.new("Sound")
sound.Parent = killer.Head
sound.SoundId = 12345678
There is a feature that should be built into the Sound called RollOffMaxDistance. This controls how many studs away a player can hear that sound. You can read about it here: https://developer.roblox.com/en-us/api-reference/property/Sound/RollOffMaxDistance
Then, to make only survivors hear the sound, you will want to use a LocalScript.
You will want to write something similar to this:
local killer = "none"
local players = game.Players:GetChildren()
for i = 1, #players do
if players[i].Team == "Killer" then
killer = players[i].Name
end
end
local player = game.Players.LocalPlayer
local killerChar = game.Workspace:FindFirstChild(killer)
local sound = killerChar.Head:WaitForChild("killerSound")
if player.Team == "Killers" then
sound.Volume = 0
end
if player.Team == "Survivors" then
sound.Volume = 0.5
end
I hope this helps! Don't hesitate to ask if you have any questions!
~Amanda314159
EDIT:
No worries! To make the killer variable, you will want this in your main script somewhere:
local players = game.Players:GetChildren()
local killer = players[math.random(1,#players)]
local killerChar = game.Workspace:WaitForChild(killer.Name)
print(killer.Name.. " is the killer!")
local sound = game.ReplicatedStorage:WaitForChild("killerSound"):Clone()
sound.Parent = killerChar:WaitForChild("Head")
Where it says fire remote event, you will want to fire a remote event to activate a localscript containing the second chunk of code that I wrote.
1 comment
Oh yeah, I would prefer it if only the survivors could hear the music and not the killer team.