I want to create a script that can check the stage number and if it’s in a specific range, play music, if it’s in another range, play another song, would this be the best code to use?
Group1 = {
1;
2;
3;
4;
5;
6;
7;
8;
9;
10;
}
local ID = script.Sound.SoundId
local Volume = script.Sound.Volume
game.Players.PlayerAdded:Connect(function(Player)
if script.Parent.Parent.Parent:FindFirstChild("leaderstats"):FindFirstChild("Stage").Value == Group1 then
ID = "rbxassetid://3182738096"
Volume = 2.5
end
end)
Here the tutorial:
make a Part and name it Area. He should be flat on the ground. Make a sound inside the part. Make the part CanCollide false and Anchored true.
Then Group it and rename the group Areas. Copy the part (Area) and make it in the same group.
then make a localsript into starterCharcaterScript ==>
local sound = Instance.new(“Sound”, script)
sound.Looped = true
local char = script.Parent
local hrp = char:WaitForChild(“HumanoidRootPart”)
local areasGroup = workspace:WaitForChild(“Areas”)
local raycast = Ray.new(hrp.Position, hrp.CFrame.UpVector * -1000)
local part = workspace:FindPartOnRayWithWhitelist(raycast, {areasGroup})
if part and part.Parent == areasGroup then
if part ~= currentArea then
currentArea = part
sound.SoundId = currentArea.Music.SoundId
sound:Play()
end
else
currentArea = nil
sound:Stop()
end
end)
thats all.
When you touch the Part, the music plays.
You could try to do this (in a local script inside the playergui):
local musics = script -- Change to where you want your musics to be.
local plr = game.Players.LocalPlayer
local obbystatus = plr:WaitForChild("ObbyStatus") -- Change to whatever the value is.
local selectedMusic = nil
obbystatus.Changed:Connect(function()
selectedMusic = musics[obbystatus.Value]
selectedMusic:Play()
for i,v in pairs(musics:GetChildren()) do
if v ~= selectedMusic then
v:Stop()
end
end
end)
I haven’t tested it as I am currently celebrating the New Year and I kind of rushed this script.
Sorry for the wait and happy New Year!
(I saw you liked my post, you might mark it as a Solution if it worked, if it didn’t, let me know!)