for some reason my peace music doesn’t play when im on the map canada
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local music = game.SoundService:WaitForChild("snake")
local music2 = game.SoundService:WaitForChild("CROW")
local TS = game:GetService("TweenService")
local peace = game.SoundService:WaitForChild("peace")
local musicplaying = false
local musicenabled = player:WaitForChild("PlayerScripts"):WaitForChild("thememsuic")
local combatenabled = player:WaitForChild("PlayerScripts"):WaitForChild("MusicEnabled")
local muscicombatplaying = char:WaitForChild("playingthemusicvomat")
local currentMusic = nil
local button = script.Parent
button.MouseButton1Click:Connect(function()
task.wait(0.5)
musicenabled.Value = not musicenabled.Value
if not musicenabled.Value then
music:Stop()
music2:Stop()
musicplaying = false
end
if musicenabled.Value then
button.BackgroundColor3 = Color3.new(0.309804, 0.45098, 0)
else
button.BackgroundColor3 = Color3.new(0.309804, 0, 0)
end
end)
local function CharacterAdded()
music:Stop()
peace:Stop()
music2:Stop()
if musicenabled.Value then
button.BackgroundColor3 = Color3.new(0.309804, 0.45098, 0)
else
button.BackgroundColor3 = Color3.new(0.309804, 0, 0)
end
end
local function PlayerAdded()
player.CharacterAdded:Connect(CharacterAdded)
if char then
CharacterAdded(char)
end
end
player.CharacterAdded:Connect(CharacterAdded)
for i,v in pairs(game.Players:GetPlayers()) do
print("bro what??")
PlayerAdded(v)
end
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")
local currentSound
local currentZoneName = nil
local musicMap = {
CROW = game:GetService("SoundService"):WaitForChild("CROW"),
Canada = game:GetService("SoundService"):WaitForChild("peace"),
snake = game:GetService("SoundService"):WaitForChild("snake")
}
player.CharacterAdded:Connect(function(char)
character = char
root = char:WaitForChild("HumanoidRootPart")
end)
while true do
task.wait(3)
if musicenabled.Value and muscicombatplaying.Value == false then
local closestZone = nil
local closestDistance = math.huge
for _, folder in pairs(workspace:WaitForChild("Maps"):GetDescendants()) do
if folder:IsA("Folder") then
local part = folder:FindFirstChild("OSTPLAY", true)
if part then
print("FOUND ZONE:", folder.Name)
local distance = (root.Position - part.Position).Magnitude
if distance < 200 and distance < closestDistance then
print("PLAYER IS IN ZONE:", folder.Name)
closestDistance = distance
closestZone = folder
end
end
end
end
if closestZone and closestZone.Name ~= currentZoneName then
local playsound = musicMap[closestZone.Name]
print("Playing:", closestZone.Name)
if playsound then
if currentSound then
currentSound:Stop()
end
playsound:Play()
currentSound = playsound
currentZoneName = closestZone.Name
else
warn("No sound found for:", closestZone.Name)
end
end
end
end
the music only plays in crow, not snake or canada, they do detect the part in crow and canada and snake but for canada and snake it still doesn’t play
Your script (from a quick glance) requires that the folder Canada has an ‘OSTPLAY’ part in it.
If the ‘OSTPLAY’ part isnt inside the Canada map, it won’t play.
Your fixes are either add the OSTPLAY into the Canada folder, or just handle maps without the OSTPLAY parts.
You can also debug with this:
elseif folder.Name == "Canada" and currentMusic ~= "Canada" then
print("Playing Canada music!")
print("musicenabled:", musicenabled.Value)
print("muscicombatplaying:", muscicombatplaying.Value)
peace:Play()
-- etc
end
is musicenabled is false, music wont play.
if the combat music is playing, it wont play.
if the ‘peace’ sound isnt loaded, it might fail silently too.
‘peace’ could also already be playing too, and it won’t restart if you call :Play() again
or, one of the volumes are 0.
theres a block in canada that has ostplay and i walk on it, crow music only plays and musicenabled is not false, none of the volumes are at 0, sooo erm ye.. a
-- StarterPlayerScripts/MusicScript
task.wait(3)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid") task.wait(1)
local musicenabled = player:WaitForChild("PlayerScripts"):WaitForChild("thememsuic")
local combatenabled = player:WaitForChild("PlayerScripts"):WaitForChild("MusicEnabled")
local combatMusicPlaying = character:WaitForChild("playingthemusicvomat")
local ss = game:GetService("SoundService")
local ts = game:GetService("TweenService")
local button = script.Parent
local currentZoneName = nil
local musicplaying = false
local currentSound = nil
local crowSound = ss:WaitForChild("CROW")
local peaceSound = ss:WaitForChild("peace")
local snakeSound = ss:WaitForChild("snake")
local musicMap = {
CROW = crowSound,
Canada = peaceSound,
snake = snakeSound
}
local function CharacterAdded()
crowSound:Stop()
peaceSound:Stop()
snakeSound:Stop()
if musicenabled.Value then
button.BackgroundColor3 = Color3.new(0.309804, 0.45098, 0)
else
button.BackgroundColor3 = Color3.new(0.309804, 0, 0)
end
end
player.CharacterAdded:Connect(function(newCharacter)
character = newCharacter
combatMusicPlaying = newCharacter:WaitForChild("playingthemusicvomat")
CharacterAdded()
end)
CharacterAdded()
button.MouseButton1Click:Connect(function()
task.wait(0.5)
musicenabled.Value = not musicenabled.Value
if not musicenabled.Value then
crowSound:Stop()
snakeSound:Stop()
peaceSound:Stop()
musicplaying = false
end
if musicenabled.Value then
button.BackgroundColor3 = Color3.new(0.309804, 0.45098, 0)
else
button.BackgroundColor3 = Color3.new(0.309804, 0, 0)
end
end)
while true do
task.wait(3)
local root = character and character:FindFirstChild("HumanoidRootPart")
if root and musicenabled.Value and combatMusicPlaying.Value == false then
local closestZone = nil
local closestDistance = math.huge
for _, folder in pairs(workspace:WaitForChild("Maps"):GetDescendants()) do
if folder:IsA("Folder") then
local part = folder:FindFirstChild("OSTPLAY", true)
if part then
print("FOUND ZONE:", folder.Name)
local distance = (root.Position - part.Position).Magnitude
if distance < 200 and distance < closestDistance then
print("PLAYER IS IN ZONE:", folder.Name)
closestDistance = distance
closestZone = folder
end
end
end
end
if closestZone and closestZone.Name ~= currentZoneName then
local playsound = musicMap[closestZone.Name]
print("Playing:", closestZone.Name)
if playsound then
if currentSound then
currentSound:Stop()
end
playsound:Play()
currentSound = playsound
currentZoneName = closestZone.Name
else
warn("No sound found for:", closestZone.Name)
end
end
end
end
A few print tests here, so you see what it is called.
Once you walk into the canada zone paste exactly what prints and the musicMap keys.
Why are these names so inconsistent.. CROW, Canada, snake.. All caps, a cap, no caps.
Pick a style and stick with it. Are these huge sounds.. they take time to load. This don’t need to run right away drop a task.wait(3) or 4 5 up top ..
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local music = game.SoundService:WaitForChild("snake")
local music2 = game.SoundService:WaitForChild("CROW")
local TS = game:GetService("TweenService")
local peace = game.SoundService:WaitForChild("peace")
local musicplaying = false
local musicenabled = player:WaitForChild("PlayerScripts"):WaitForChild("thememsuic")
local combatenabled = player:WaitForChild("PlayerScripts"):WaitForChild("MusicEnabled")
local muscicombatplaying = char:WaitForChild("playingthemusicvomat")
local currentMusic = nil
local button = script.Parent
button.MouseButton1Click:Connect(function()
task.wait(0.5)
musicenabled.Value = not musicenabled.Value
if not musicenabled.Value then
music:Stop()
music2:Stop()
musicplaying = false
end
if musicenabled.Value then
button.BackgroundColor3 = Color3.new(0.309804, 0.45098, 0)
else
button.BackgroundColor3 = Color3.new(0.309804, 0, 0)
end
end)
local function CharacterAdded()
music:Stop()
peace:Stop()
music2:Stop()
if musicenabled.Value then
button.BackgroundColor3 = Color3.new(0.309804, 0.45098, 0)
else
button.BackgroundColor3 = Color3.new(0.309804, 0, 0)
end
end
local function PlayerAdded()
player.CharacterAdded:Connect(CharacterAdded)
if char then
CharacterAdded(char)
end
end
player.CharacterAdded:Connect(CharacterAdded)
for i,v in pairs(game.Players:GetPlayers()) do
print("bro what??")
PlayerAdded(v)
end
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")
local currentSound
local currentZoneName = nil
local musicMap = {
crow = game:WaitForChild("SoundService"):WaitForChild("CROW"),
canada = game:WaitForChild("SoundService"):WaitForChild("peace"),
snake = game:WaitForChild("SoundService"):WaitForChild("snake")
}
player.CharacterAdded:Connect(function(char)
character = char
root = char:WaitForChild("HumanoidRootPart")
end)
while true do
task.wait(3)
if musicenabled.Value and muscicombatplaying.Value == false then
local closestZone = nil
local closestDistance = math.huge
for _, folder in pairs(workspace:WaitForChild("Maps"):GetChildren()) do
if folder:IsA("Folder") then
local part = folder:FindFirstChild("OSTPLAY", true)
if part then
print("FOUND ZONE:", folder.Name)
local distance = (root.Position - part.Position).Magnitude
if distance < 200 and distance < closestDistance then
print("PLAYER IS IN ZONE:", folder.Name)
closestDistance = distance
closestZone = folder
end
end
end
end
if closestZone then
local zoneName = string.lower(closestZone.Name)
local newSound = musicMap[zoneName]
if newSound then
-- Only switch if different
if currentZoneName ~= zoneName then
if currentSound then
currentSound:Stop()
end
newSound:Play()
currentSound = newSound
currentZoneName = zoneName
print("Now playing:", zoneName)
end
else
warn("No sound mapped for zone:", closestZone.Name)
end
end
end
end
NOW it plays but, i have a small issue where im walking inside the ostplay, like im walking while im inside the part named ostplay but plays when near in the middle of the part
You’re checking the part position, and that is the center of the part..
Maybe try..
swap this
local distance = (root.Position - part.Position).Magnitude
if distance < 200 and distance < closestDistance then
for this
local partCFrame = part.CFrame
local partSize = part.Size
local localPosition = partCFrame:PointToObjectSpace(root.Position)
if math.abs(localPosition.X) < partSize.X / 2 and
math.abs(localPosition.Y) < partSize.Y / 2 and
math.abs(localPosition.Z) < partSize.Z / 2 then
I see string lower saved you. That is still pointing at the names are not the same.
Again the odd way of naming them..
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local music = game.SoundService:WaitForChild("snake")
local music2 = game.SoundService:WaitForChild("CROWs")
local TS = game:GetService("TweenService")
local peace = game.SoundService:WaitForChild("peace")
local musicplaying = false
local musicenabled = player:WaitForChild("PlayerScripts"):WaitForChild("thememsuic")
local combatenabled = player:WaitForChild("PlayerScripts"):WaitForChild("MusicEnabled")
local muscicombatplaying = char:WaitForChild("playingthemusicvomat")
local currentMusic = nil
local button = script.Parent
button.MouseButton1Click:Connect(function()
task.wait(0.5)
musicenabled.Value = not musicenabled.Value
if not musicenabled.Value then
music:Stop()
music2:Stop()
musicplaying = false
end
if musicenabled.Value then
button.BackgroundColor3 = Color3.new(0.309804, 0.45098, 0)
else
button.BackgroundColor3 = Color3.new(0.309804, 0, 0)
end
end)
local function CharacterAdded()
music:Stop()
peace:Stop()
music2:Stop()
if musicenabled.Value then
button.BackgroundColor3 = Color3.new(0.309804, 0.45098, 0)
else
button.BackgroundColor3 = Color3.new(0.309804, 0, 0)
end
end
local function PlayerAdded()
player.CharacterAdded:Connect(CharacterAdded)
if char then
CharacterAdded(char)
end
end
player.CharacterAdded:Connect(CharacterAdded)
for i,v in pairs(game.Players:GetPlayers()) do
print("bro what??")
PlayerAdded(v)
end
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")
local currentSound
local currentZoneName = nil
local musicMap = {
crow = music2,
canada = peace,
snake = music
}
player.CharacterAdded:Connect(function(char)
character = char
root = char:WaitForChild("HumanoidRootPart")
end)
while true do
task.wait(3)
if musicenabled.Value and muscicombatplaying.Value == false then
local closestZone = nil
local closestDistance = math.huge
for _, folder in pairs(workspace:WaitForChild("Maps"):GetChildren()) do
if folder:IsA("Folder") then
local part = folder:FindFirstChild("OSTPLAY", true)
if part then
local partCFrame = part.CFrame
local partSize = part.Size
local localPosition = partCFrame:PointToObjectSpace(root.Position)
if math.abs(localPosition.X) < partSize.X / 2 and
math.abs(localPosition.Y) < partSize.Y / 2 and
math.abs(localPosition.Z) < partSize.Z / 2 then
print("PLAYER IS IN ZONE:", folder.Name)
closestZone = folder
end
end
end
end
if closestZone then
local zoneName = string.lower(closestZone.Name)
local newSound = musicMap[zoneName]
if newSound then
if currentZoneName ~= zoneName then
if currentSound then
currentSound:Stop()
end
newSound:Play()
currentSound = newSound
currentZoneName = zoneName
print("Now playing:", zoneName)
end
else
warn("No sound mapped for zone:", closestZone.Name)
end
end
end
end
soo i tried doing, canada does work but now crow and snake doesn’t play when im near or walking on their ostplay parts
-- StarterPlayerScripts.LocalScript
local rs = game:GetService("RunService")
local ts = game:GetService("TweenService")
local ss = game:GetService("SoundService")
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
local zones = {
{part = workspace:WaitForChild("Zone1"), sound = ss:WaitForChild("Crow")},
{part = workspace:WaitForChild("Zone2"), sound = ss:WaitForChild("Snake")},
{part = workspace:WaitForChild("Zone3"), sound = ss:WaitForChild("Peace")}
}
local currentZone = nil
local fadeInfo = TweenInfo.new(2, Enum.EasingStyle.Linear)
local function FadeOut(sound)
local tween = ts:Create(sound, fadeInfo, {Volume = 0})
tween:Play()
tween.Completed:Connect(function()
sound:Stop() sound.Volume = 1
end)
end
while true do rs.Stepped:Wait()
local foundZone = nil
for _, zone in pairs(zones) do
for _, p in pairs(workspace:GetPartsInPart(zone.part)) do
if p.Parent == localPlayer.Character then
foundZone = zone
break
end
end
if foundZone then break end
end
if foundZone ~= currentZone then
if currentZone then FadeOut(currentZone.sound) end
if foundZone then foundZone.sound:Play() end
currentZone = foundZone
end
end
The “zones” here are a part they are walking into.
Don’t even need to see them, if you don’t want them seen. This was for testing.
This is an alternative to TouchEnded that isn’t going to fail.
Depending on what you’re doing this may work.. it’s a bit sloppy. I don’t see why you’re having so many problems. Maybe cut that down to get it working then add the other things. Always easier to add to working.