Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Playing Music in Certain Areas not Working?

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

0

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

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.