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

How to stop a part from being created?

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

2 comments

0

if not workspace:FindFirstChild("SOUND NAME") then (clone script) end

0

Confused on what you're asking, can you clarify -- also, don't set parents from Instance.new().

1 answer

✓ Accepted answer

Hello GamingHDstudios.

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.


If this has helped you or somebody else you know, click 'Accept Answer'.

1 comment

0

Also if it keeps and keeps on replaying the start of an ID, add a debounce.

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