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

How to stop a part from being created?

Asked by 5 years ago
Edited 5 years ago

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
0
if not workspace:FindFirstChild("SOUND NAME") then (clone script) end yHasteeD 1819 — 5y
0
Confused on what you're asking, can you clarify -- also, don't set parents from Instance.new(). SummerEquinox 643 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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'.
0
Also if it keeps and keeps on replaying the start of an ID, add a debounce. TheOnlySmarts 233 — 5y
Ad

Answer this question