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.

1 comment
You would be better off using a local script since this is for the client only