Music Areas in Roblox Studio
Hello Robloxians, in this video I have Areas with Music for you!!
Feel free to pause the video if you need to!
[SCRIPT]
local sound = Instance.new("Sound", script)
sound.Looped = true
local char = script.Parent
local hrp = char:WaitForChild("HumanoidRootPart")
local areasGroup = workspace:WaitForChild("Areas")
local currentArea = nil
game:GetService("RunService").Heartbeat:Connect(function()
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)
TAGS:
#Roblox #RobloxStudio #Tutorial