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

Sound changer trigger not working ?

Asked by
Bulvyte 388 Moderation Voter
8 years ago

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 !

0
can you please post the exact error? TopDev 0 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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.

0
My sound is named "Forest" when he passes trough Forest is not a valid member of Player... Line 11 Bulvyte 388 — 8y
0
Are you sure that the sound inside Player is actually called 'Forest'? Is it being cloned into the player or created with a script? IDidMakeThat 1135 — 8y
0
as u can see... in the script it clones it into the player Bulvyte 388 — 8y
0
the thing is if i remove the line it works because if i write player.Forest:Stop() it wants to stop the sound included in script but i want to stop the other triggers sound and the other trigger stops this sound. This is a mind **** which i call it :D help meeeee Bulvyte 388 — 8y
View all comments (5 more)
0
http://prntscr.com/8bw3qy << here it works but i just want it to stop other triggers sound and play my new song when touched Bulvyte 388 — 8y
0
please add me, because it's very hard to explain i'm lithuanian i don't know good english so i'm sorry Bulvyte 388 — 8y
0
Anyone ? ... Bulvyte 388 — 8y
0
this is such pain no ones trying to help only everyone knows the easy scripts but not the confusing ones Bulvyte 388 — 8y
0
Hello bul. Can you post the exact error you're getting please? TopDev 0 — 8y
Ad

Answer this question