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

Playing Music in Certain Areas not Working?

Asked by 6 years ago
Edited 6 years ago
script.Parent.Touched:connect(function(hit)
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if hum then
        local char = hum.Parent
        local plr = game.Players:GetPlayerFromCharacter(char)
        if plr then
            local gui = plr:FindFirstChild("PlayerGui")
            local music = gui:FindFirstChild("Music") --variable
            local forestmusic = music:FindFirstChild("ForestMusic") --error
            local townmusic = music:FindFirstChild("TownMusic")
            forestmusic.Volume = 0
            townmusic.Volume = 1
        end
    end
end)

My script works in studio but not in a game. The error is saying that the "music" variable does not exist but it is clearly defined in the script. I don't understand what is wrong.

0
You would be better off using a local script since this is for the client only User#5423 17 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Try this

            local music = gui:WaitForChild("Music")
0
Didn't work. InfernoExeuctioner 126 — 6y
Ad

Answer this question