I made a script so whenever you enter a area in the game music is created, but as long as the player is inside the part, music is being infinitely created.
local S1 = Instance.new ("Sound",workspace) if S1 == true then local S1 = Instance.new ("Sound",workspace)= false
Your issue is a simple fix.
You can make a Touched
function and get the hit.Parent
, and check if the hit.Parent
is a Humanoid
or Player
using the code below.
if hit.Parent:FindFirstChild("Humanoid")
And then play the Sound
. This is simply done using the function, Play()
.
It would be done in terms like this.
workspace.Sound:Play()
Now that was an example, your Sound
might be a different name.
Also it is recommended to use workspace
instead of game.Workspace
as it takes less lines of code and is more clean.
So now that we've made the first Part's Script
, let's make the second's.
In our other Part
we'll do the same thing, which is.
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then workspace.Sound:Play() end end)
But instead, we'll change the Play()
function to a Stop()
function, stopping the music being played.
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then workspace.Sound:Stop() end end)
Hopefully this has helped.