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

How Do I Put Two Scripts Into One Script?

Asked by
ImfaoXD 158
9 years ago

How do I put these two scripts into one script? I want to put the sparkles script with the sound script so that when you click the brick, both will work at the same time. For example; when you click the brick, the sparkles will come out and the sound will play. But also, how do I make it sparkles for a short period of time without sparkling forever? I try to put the two script in together and it isn't working. Can somebody help me?

(Sparkles Script) I don't know if I did this right, but I want the sparkles script to sparkles for a short period of time instead of sparkling forever when click.

function onClicked()

    script.Parent.Sparkles.Enabled = true
    wait(3)
    script.Parent.Sparkles.Enabled = false
  end

  script.Parent.ClickDetector.MouseClick:connect(onClicked)

And (Sound Script)

Brick = script.Parent
Sound = Brick.Sound
Debounce = false

function onClicked()
    if not Debounce then 
        Debounce = true 
        Sound:Play()
        wait(Sound.TimeLength) 
        Debounce = false 
    end 
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Thank you for your helps!

0
It's literally a matter of copy-pasting the code from the first function into the second function. Perci1 4988 — 9y

2 answers

Log in to vote
1
Answered by
smd34 30
9 years ago

Try this:

local Brick = script.Parent

local Sound = Brick.Sound

local Debounce = false --remove local if it doesnt work.

function onClicked()
    script.Parent.Sparkles.Enabled = true
    wait(3)
    script.Parent.Sparkles.Enabled = false
if not Debounce then
        Debounce = true
        Sound:Play()
        wait(Sound.TimeLength)
        Debounce = false
    end
  end
  script.Parent.ClickDetector.MouseClick:connect(onClicked)

Ad
Log in to vote
0
Answered by 9 years ago

Try this:

Brick = script.Parent
Sound = Brick.Sound
Debounce = false
function onClicked()
if not Debounce then
Debounce = true
Sound:Play()
script.Parent.Sparkles.Enabled = true
wait(Sound.TimeLength)
Debounce = false
script.Parent.Sparkles.Enabled = false
end

Answer this question