So thats what i want to do this haven't been solved 2 weeks ago because nobody answered so im posting this again... What i want it to do is when u pass a trigger song plays. When u pass another trigger it stops and plays a new song. Like a biome changer song.
Trigger1
script:
local brick = script.Parent local sound = script.Parent.Forest debounce = false brick.Touched:connect(function(hit) player = game.Players:GetPlayerFromCharacter(hit.Parent) if player and not debounce then debounce = true player = sound:Clone() player.Parent = player.PlayerGui player.Snow:Stop() -- < If song was already in biome stops it player:Play() wait(0.1) debounce = false end end)
Trigger2
script:
local brick = script.Parent local sound = script.Parent.Snow debounce = false brick.Touched:connect(function(hit) player = game.Players:GetPlayerFromCharacter(hit.Parent) if player and not debounce then debounce = true player = sound:Clone() player.Parent = player.PlayerGui player.Forest:Stop() -- < if song was already playing stops it player:Play() wait(0.1) debounce = false end end)
the thing is it doesn't work gives me PlayerGui is not a valid of Sound or something like that... idk help me please! i am lost and i really need assistance, this is an important script thank you all very much i appreciate for your work !
One thing I see is that you are overwriting the variable player
in both trigger scripts. You should replace this:
player = sound:Clone() player.Parent = player.PlayerGui player.Forest:Stop() player:Play()
with something like this:
local sound = sound:Clone() -- Note the use of local variables. Global variables are evil. sound.Parent = player.PlayerGui player.Forest:Stop() -- < if song was already playing stops it sound:Play()
That should hopefully fix the main issue at hand.