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

Want variable to activate once?

Asked by 6 years ago
Edited 6 years ago

I have a script like this:

function onClick(click) 
    script.Parent.Parent.BrickColor = BrickColor.new(255,0,0)
    print("Wave generator Loaded") -- Don't remove this shtuffz, it helps reduce lag a little
wait(0.5)
print("Wave generator Loading 10% |I         |")
wait(1.0)
print("Wave generator Loading 13% |I         |")
wait(1.0)
print("Wave generator Loading 17% |I         |")
wait(1.0)
print("Wave generator Loading 21% |II        |")
wait(0.5)
print("Wave generator Loading 31% |III       |")
wait(0.2)
print("Wave generator Loading 39% |III       |")
wait(0.2)
print("Wave generator Loading 48% |IIII      |")
wait(0.2)
print("Wave generator Loading 53% |IIIII     |")
wait(0.2)
print("Wave generator Loading 67% |IIIIII    |")
wait(0.2)
print("Wave generator Loading 81% |IIIIIIII  |")
wait(0.2)
print("Wave generator Loading 95% |IIIIIIIII |")
wait(0.01)
print("Wave generator Loading 100% |IIIIIIIII|")
print("Wave loaded")
while true do
    wait(5)
local behs = game.Lighting.Army:clone()
behs.Parent = Workspace
behs:makeJoints()
end
end

script.Parent.MouseClick:connect(onClick)

I want this script to happen only once.

0
Please remove the fake loading lol. RubenKan 3615 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

This is simple. We can use the Wait() method on RBXScriptSignals (ex: MouseClick). It waits until the event been fired. To apply this in your code, you can do

script.Parent.MouseClick:Wait()
script.Parent.Parent.BrickColor = BrickColor.new(255,0,0)
print("Wave generator Loaded") -- Don't remove this shtuffz, it helps reduce lag a little
wait(0.5)
print("Wave generator Loading 10% |I         |")
wait(1.0)
print("Wave generator Loading 13% |I         |")
wait(1.0)
print("Wave generator Loading 17% |I         |")
wait(1.0)
print("Wave generator Loading 21% |II        |")
wait(0.5)
print("Wave generator Loading 31% |III       |")
wait(0.2)
print("Wave generator Loading 39% |III       |")
wait(0.2)
print("Wave generator Loading 48% |IIII      |")
wait(0.2)
print("Wave generator Loading 53% |IIIII     |")
wait(0.2)
print("Wave generator Loading 67% |IIIIII    |")
wait(0.2)
print("Wave generator Loading 81% |IIIIIIII  |")
wait(0.2)
print("Wave generator Loading 95% |IIIIIIIII |")
wait(0.01)
print("Wave generator Loading 100% |IIIIIIIII|")
print("Wave loaded")
while true do
    wait(5)
    local behs = game.Lighting.Army:clone()
    behs.Parent = Workspace
    behs:makeJoints()
end

Also, print statements do not reduce lag. You should also store things in ReplicatedStorage.

Hope this helps!

Ad
Log in to vote
0
Answered by 6 years ago

Now, a simple way to do this is with a coroutine.

function onClick(click) 
    local Script = coroutine.create(function()
    script.Parent.Parent.BrickColor = BrickColor.new(255,0,0)
    while true do
    wait(5)
local behs = game.Lighting.Army:clone()
behs.Parent = Workspace
behs:makeJoints()
wait(5)
end
    end)

script.Parent.MouseClick:connect(onClick)



If this did work, please put my answered as "answer". thanks! also try using your own models instead of free ones ;)

Answer this question