Woah that death sound was super cool. How did you do that?
it is from the module script that is the parent of the script that has all of the sounds and main code
@Wertyhappy27
You can’t require a LocalScript, only ModuleScript.
@dispeller
Nope, but you can use this:
local function IsPointInPart_Fn(Point, Part) -- Cylinder
local relPos = Part.CFrame:PointToObjectSpace(Point)
local distFromCenter = Vector2_New(relPos.Y, relPos.Z).Magnitude
local radius = Part.Size.Y*.5
return Math_Abs(relPos.X) < Part.Size.X*.5 and distFromCenter < radius
end
credits to my mentor
You could also use GetTouchingParts.
Personally, the first time I made an area music system, I used Region3.
I looped this every 5 seconds. That way, each piece of music played for at least 5 seconds. Kinda prevents breaking immersion
function UpdateRegion()
local inRegion = false
for i,v in pairs(game.ReplicatedStorage.BorderBlocks:GetChildren()) do
local min = v.Position - (0.5 * v.Size)
local max = v.Position + (0.5 * v.Size)
local region = Region3.new(min, max)
local whitelist = {Player.Character}
local parts = workspace:FindPartsInRegion3WithWhiteList(region,
whitelist, 100)
--warn(#parts)
for partIndex, part in pairs(parts) do
--print('PART NAME!'..v.Name)
if part.Parent == Player.Character then
inRegion = true
if regionCurrentlyInside ~= v.Name then
regionCurrentlyInside = v.Name
print'CHANGED REGION!'
end
end
end
end
if not inRegion then
if regionCurrentlyInside ~= 'Outside' then
regionCurrentlyInside = 'Outside'
print'went outside'
end
end
end
There was also this module called Zone+ that might be useful.
Lots of ways to do this.
Cool module!
I noticed that in post #6
I also mentioned that using Region3 is tedious and not Non-Programmer friendly, you can refer back to post #6 for more details.
indeed there are multiple ways of achieving the same thing~
If region 3 is “tedious”, isn’t it your job to make it easier? I wouldn’t recommend this to anyone, .touched event is unreliable.
If I were you, I would use region 3 and get players to define zones using parts, then calculate region3 zone for them. Not so hard is it?
Despite the comments about using region 3 and about using TouchedEvent not being reliable, I thank you for this resource that can improve my scripting abilities, continue doing what you do best .
Also is there a way to turn this into a music player where you can just insert the song id and play different types of music such as a party setting etc and how would you go about doing that?
I added it how you had it set up in your game, i have no idea what is wrong
This is so cool! Thx bro! I like this
Hey man, wonderful script. However it seems there is a problem for me while using it. Whenever a character dies, and respawns, the music stops. It used to work just fine, but after I changed the volume in the Module Script it seemed to have messed the script up? Idrk what went wrong.
Here’s the script
This did the trick for me, there’s a mistake in the module:
Replace the Character_Added function with:
local function Character_Added(Character)
if (not cache[Character]) then
cache[Character] = tick()
Cha = Character; Hum = Cha:WaitForChild('Humanoid'); RootPart = Cha:WaitForChild("HumanoidRootPart")
HumDied_Connection = Hum.Died:Connect(Humanoid_Died)
end
end
Yep, also found out it was because I altered the respawn time from 5, to 1 second. Idk, if putting this in would fix, but at least you found something wrong, and fixed it
Thanks alot, I’d love to use this in my game!
Keep it up! Love this resource. I’m probably gonna use it in my game.
Thanks, this is very helpful! Definitely helps add some atmosphere.
Could you add a few features,
- mute button (cant hear music)
- multiple tracks for an area, play randomly
- Gui on the screen that says what is playing, you can put a value in the music object that has the title and artist, if nothing is there, then it doesn’t display.
I managed to glitch it, if you use MoveTo() on character that is inside the zone, and the HumanoidRootPart is Anchored, the music still plays. Please fix
How can I make this useable with unions? I have areas that overlap and was wondering how I can work around the music going at the same time.
Here’s a script I use to have multiple tracks on in the part, I just put it into the Local Script.
local musicFolder = script.Music
local availableMusic = musicFolder:GetChildren()
local currentTrack = script.Parent.ModuleScript.Musics.Simp
if game:IsLoaded() then
wait(5)
while true do
local randomTrack = availableMusic[math.random(1,#availableMusic)]
wait(2)
currentTrack.SoundId = randomTrack.SoundId
currentTrack:Play()
currentTrack.Ended:Wait()
end
end
Also changed the part to pause the music instead of stopping it entirely, so that it’s
- a smooth transition
and - doesn’t glitch out
Hi there, I’m currently using the script for a commission, so thank you for the opportunity to use it!
Although I did encounter an issue; Sometimes the sound doesn’t play and I don’t know why it happens either. My guess is that it happens after resetting inside of the area, but I can’t be too sure.