I tried using roblox AI to help with this and it didnt help
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local union = Workspace.Folders.Buildings["Dance Party"]["MusicPlayer Union"]
local musicSound = union:FindFirstChild("Music")
local hummingSound = union:FindFirstChild("Humming")
local LocalPlayer = Players.LocalPlayer
local function cloneSound(sound)
local newSound = sound:Clone()
newSound.Parent = LocalPlayer.Character
return newSound
end
local playing = false
local musicClone, hummingClone
local function playAlternatingSounds()
playing = true
while playing do
if musicClone and hummingClone then
musicClone:Play()
while musicClone.IsPlaying and playing do
task.wait(0.1)
end
musicClone:Stop()
if not playing then break end
hummingClone:Play()
while hummingClone.IsPlaying and playing do
task.wait(0.1)
end
hummingClone:Stop()
else
break
end
end
end
local function onTouched(otherPart)
local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
if otherPart:IsDescendantOf(character) and not playing then
-- Clone sounds to character so only this player hears them
musicClone = cloneSound(musicSound)
hummingClone = cloneSound(hummingSound)
playAlternatingSounds()
end
end
local function onTouchEnded(otherPart)
local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
if otherPart:IsDescendantOf(character) and playing then
playing = false
if musicClone then
musicClone:Stop()
musicClone:Destroy()
musicClone = nil
end
if hummingClone then
hummingClone:Stop()
hummingClone:Destroy()
hummingClone = nil
end
end
end
union.Touched:Connect(onTouched)
union.TouchEnded:Connect(onTouchEnded)
the script i gave for reference:
local AreaSounds = Instance.new("Sound", script)
AreaSounds.Looped = true
local plr = script.Parent
local Presser = plr:WaitForChild("HumanoidRootPart")
local DifferentAreas = workspace:WaitForChild("Areas")
local CurrentArea = nil
game:GetService("RunService").Heartbeat:Connect(function()
local raycast = Ray.new(Presser.Position, Presser.CFrame.UpVector * -1000)
local part = workspace:FindPartOnRayWithWhitelist(raycast, {DifferentAreas})
if part and part.Parent == DifferentAreas then
if part ~= CurrentArea then
CurrentArea = part
AreaSounds.SoundId = CurrentArea.Sound.SoundId
AreaSounds:Play()
end
else
CurrentArea = nil
AreaSounds:Stop()
end
end)
What is supposed to happen is that when the player enters the zone, two sounds should start playing one after the other, only for that player. When the player leaves the zone, the audio should stop. I made two parts into a union, and this is a LocalScript inside StarterCharacterScripts. I would really appreciate any help.
Right now, the audio plays as soon as you join the game and gets louder as you approach the area, but it does not play when the player is actually inside the zone.
asked it to use this script to fix the issue as reference which i added in the bottom of the block above


