#different music plays in a specific area
1 messages · Page 1 of 1 (latest)
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local musicPart = workspace:WaitForChild("CatzMusicPart")
local music = Instance.new("Sound")
music.Name = "CatzLoop"
music.SoundId = "rbxassetid://1837768517"
music.Looped = true
music.Volume = 0.5
music.RollOffMode = Enum.RollOffMode.None
music.Parent = workspace.CurrentCamera
local function isInside(part, position)
local rel = part.CFrame:PointToObjectSpace(position)
local half = part.Size / 2
return math.abs(rel.X) <= half.X and math.abs(rel.Y) <= half.Y and math.abs(rel.Z) <= half.Z
end
local playing = false
RunService.RenderStepped:Connect(function()
local char = player.Character
local root = char and char:FindFirstChild("HumanoidRootPart")
if not root then return end
local inZone = isInside(musicPart, root.Position)
if inZone and not playing then
music:Play()
playing = true
elseif not inZone and playing then
music:Stop()
playing = false
end
end)
💾 Source Code | 📖 Documentation | 🌊 Playground ZonePlus utilises the new Spatial Query API and Whitelists to effectively determine players, parts and custom items within a zone. You can have as many zones as you like, as large as you like, with zero-to-minimal additional cost to performance. For those looking to benefit from v3 you c...
yeah ive been suggested this before for other issues and i lowkey have no idea how to use it and i read all the instructions and everything still dont know
its basically a fancy zonepart.touched:connect and touchended:connect but it does all the annoying validation and grouping and debouncing and whatnot for you
that sounds very helpful
its one of the few times i'll suggest using a 3rd party module like this, since you a beginner
its similar level to profileservice, useful for beginners, but for both of these i'd still roll my own. a beginner wont have that luxury
music zones work in a very similar way. you either set up zone boundaries like that with massive invisible parts, or you use area triggers (which can leave open situations where you enter an area and the lighting/area music/skybox area stuff doesn't trigger), but it's also waaay easier to define zones since you only need to care about entry/exit points. meh, pick your poison 🤷
pretty sure zoneplus lets you define by fixed world coordinates (enter x,y,z bounding boxes, no parts)
those are the 2 main ways of doing zones
yeah ive been trying to script using the big invisible parts
that like surround an area
yea so sometimes you'll have an odd-shaped zone that isn't a perfect cube, zoneplus can handle that
the pattern for doing that is not trivial
alr thanks for the help, ill try zoneplus again hopefully i can get it to work out