Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[Unanswered] Sound not changing when player is in area?

Asked by
yoshi8080 445 Moderation Voter
8 years ago

The only problem is that the sound doesn't change at all.

local function onPlayerEntered(newPlayer)
    local stats = Instance.new("StringValue")
    stats.Name = "Area"
    stats.Value = "Spawn"
    stats.Parent = newPlayer    
end

function onPlayerRespawned(newPlayer)
    local stats = newPlayer:FindFirstChild("Area")
    if stats == nil then
local stat = Instance.new("StringValue")
    stat.Name = "Area"
    stat.Value = "Spawn"
    stat.Parent = newPlayer 
    end
    local song1 = newPlayer.PlayerGui:FindFirstChild("Lobby")
        if song1 == nil then
local song1 = Instance.new("Sound", newPlayer.PlayerGui) 
    song1.Looped = true
    song1.Name = "Lobby"
    local Id = "rbxassetid://" 
    song1.SoundId = Id.."319731744"
    song1.Volume = .5
        song1:Play()
elseif song1 ~= nil then
    song1.Looped = true
local Id = "rbxassetid://" 
    song1.SoundId = Id.."319731744"
    song1.Volume = .5
    song1:Play()

   local song2 = newPlayer.PlayerGui:FindFirstChild("Hi")
        if song2 == nil then
    local song2 = Instance.new("Sound", newPlayer.PlayerGui)
    song2.Name = "Hi" 
    song2.Looped = true
    local Id = "rbxassetid://" 
    song2.SoundId = Id.."319731744"
    song2.Volume = .5

elseif song2 ~= nil then
    song2.Looped = true
local Id = "rbxassetid://" 
    song2.SoundId = Id.."319731744"
    song2.Volume = .5
    song2:Play()
end
end
    local stat = newPlayer:FindFirstChild("Area")
    local song = newPlayer.PlayerGui:FindFirstChild("Lobby") or newPlayer.PlayerGui:WaitForChild("Lobby")
    local songtwo = newPlayer.PlayerGui:FindFirstChild("Hi") newPlayer.PlayerGui:WaitForChild("Hi")

if stat == nil then
   local k = Instance.new("StringValue",newPlayer)
    k.Name = "Area"
else
    stat.Value = "Lobby"
    songtwo:Stop()
    song:Play()

if stat == nil then
   local k = Instance.new("StringValue",newPlayer)
    k.Name = "Area"
else
    stat.Value = "Hi"
    songtwo:Play()
    song:Stop()
end
    end
        end
function onPlayerEntered(newPlayer)
    newPlayer.Changed:connect(function (property)
        if (property == "Character") then
onPlayerRespawned(newPlayer)
end
    end)
    end

game.Players.ChildAdded:connect(onPlayerEntered)
0
Hey you used my script. Nice!! LateralLace 297 — 8y
0
It seemed to be a bit more organized and missing some stuff, however it still didn't work 100% yoshi8080 445 — 8y

2 answers

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

When changing a soundId, you need to stop the music, change the Id, then play it.

0
I have tried that, still nothing, yoshi8080 445 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

Try this

local function onPlayerEntered(newPlayer)
    local stats = Instance.new("StringValue")
    stats.Name = "Area"
    stats.Value = "Spawn"
    stats.Parent = newPlayer    
end

function onPlayerRespawned(newPlayer)
    local music = newPlayer:FindFirstChild("Sound")
        if music == nil then
local music = Instance.new("Sound", newPlayer.PlayerGui) 
    music.Looped = true
music.SoundId = "http://www.roblox.com/asset/?id=319731744" 
    music.Volume = .5
        music:Play()
elseif music ~= nil then
    music.Looped = true
    music.SoundId = "http://www.roblox.com/asset/?id=319731744" 
    music.Volume = .5
    music:Play()
end

    local stat = newPlayer:FindFirstChild("Area")

if stat == nil then
    k = Instance.new("StringValue",newPlayer)
    k.Name = "Area"
else
    stat.Value = "Lobby"
music.SoundId = "http://www.roblox.com/asset/?id=326012211" 

if stat == nil then
    k = Instance.new("StringValue",newPlayer)
    k.Name = "Area"
else
    stat.Value = "Hi"
music.SoundId = "http://www.roblox.com/asset/?id=326012211" 
end
    end
        end
function onPlayerEntered(newPlayer)
    newPlayer.Changed:connect(function (property)
        if (property == "Character") then
onPlayerRespawned(newPlayer)
end
    end)
    end

game.Players.ChildAdded:connect(onPlayerEntered)

You just created a localized sound ID but you never told the sound that you wanted it to be that ID so I helped you.

0
Workspace.Area:30: attempt to index local 'music' (a nil value) yoshi8080 445 — 8y

Answer this question