#different music plays in a specific area

1 messages · Page 1 of 1 (latest)

sharp garnet
#

i have it so in multiple different areas different music plays, but for some reason this area isn't working. can someone figure out what the issue with the script is? the user is supposed to touch the part "CatzMusicPart" and while it is being touched specific music plays. script below:

#

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)

abstract egret
#
sharp garnet
abstract egret
sharp garnet
#

that sounds very helpful

abstract egret
#

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

abstract egret
# sharp garnet that sounds very helpful

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

sharp garnet
#

that like surround an area

abstract egret
#

the pattern for doing that is not trivial

sharp garnet
#

alr thanks for the help, ill try zoneplus again hopefully i can get it to work out

stiff parcel
#

just raycast from the players feet every mille second or some small number and if it touches a part of that area the music change

#

so like