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

Hello, does anybody know how i can do this to multiple parts of the same script?

There is a randomization code that occurs for the part "taw" but I want multiple duplicated parts of "taw" to be affected by the same script. Does anybody know how I would modify this script to make it work out?

local debounce = true
local Sound = script.Parent.Parent.Parent.taw.Sound
local Light = script.Parent.Parent.Parent.taw.Light
local Particle1 = script.Parent.Parent.Parent.taw.Particle1
local Particle2 = script.Parent.Parent.Parent.taw.Particle2
local ParticleEmitter1 = script.Parent.Parent.Parent.taw.ParticleEmitter1
local ParticleEmitter2 = script.Parent.Parent.Parent.taw.ParticleEmitter2
local ParticleEmitter3 = script.Parent.Parent.Parent.taw.ParticleEmitter3
local ParticleEmitter4 = script.Parent.Parent.Parent.taw.ParticleEmitter4
local ParticleEmitter5 = script.Parent.Parent.Parent.taw.ParticleEmitter5
local ParticleEmitter6 = script.Parent.Parent.Parent.taw.ParticleEmitter6
local ParticleEmitter7 = script.Parent.Parent.Parent.taw.ParticleEmitter7
local ParticleEmitter8 = script.Parent.Parent.Parent.taw.ParticleEmitter8
local ParticleEmitter9 = script.Parent.Parent.Parent.taw.ParticleEmitter9
local ParticleEmitter10 = script.Parent.Parent.Parent.taw.ParticleEmitter10
	
script.Parent.MouseClick:Connect(function()
	local time1 = math.random (30,150) --IMPORTANT: This is how long between each shot
	local time2 = math.random(1,100) --This just picks when in that second it'll happen.

	wait (time1+time2/100)
	if debounce == true then
		debounce = false
	Sound:Play()
	Light.Enabled = true
	Particle1.Enabled = true
	Particle2.Enabled = true
	ParticleEmitter1.Enabled = true
	ParticleEmitter2.Enabled = true
	ParticleEmitter3.Enabled = true
	ParticleEmitter4.Enabled = true
	ParticleEmitter5.Enabled = true
	ParticleEmitter6.Enabled = true
	ParticleEmitter7.Enabled = true
	ParticleEmitter8.Enabled = true
	ParticleEmitter9.Enabled = true
	ParticleEmitter10.Enabled = true
	wait(0.1)
	Light.Enabled = false
	Particle1.Enabled = false
	Particle2.Enabled = false
	ParticleEmitter1.Enabled = false
	ParticleEmitter2.Enabled = false
	ParticleEmitter3.Enabled = false
	ParticleEmitter4.Enabled = false
	ParticleEmitter5.Enabled = false
	ParticleEmitter6.Enabled = false
	ParticleEmitter7.Enabled = false
	ParticleEmitter8.Enabled = false
	ParticleEmitter9.Enabled = false
	ParticleEmitter10.Enabled = false
	wait(3)
		debounce = true
	end
end)

2 answers

I would do something like this.

script.Parent.MouseClick:Connect(funtion()
	-- do time stuff
	for i,v in pairs(script.Parent.Parent.Parent.taw:GetChildren()) do
		if v:IsA'ParticleEmitter' then -- idk if particle emitter is the class but ye
			v.Enabled = true -- enables all particle emitters under taw
		end
	end
	wait() -- the wait
	-- do same thing but disable
		

1 comment

0

uh i think dat wot u mean by multiple parts e.e

No need to make it so much lines. You can just ignore the variables, we'll set it in an easier way later.

What are you gonna learn before this, is for loops, and how to match a string value together (and you're gonna make it become an Instance).

For loop, for example:

for number = 1, 10, 1 do
	print(number)
end

It prints 10 times. It goes from 1 and 2 and 3... and so on until 10, it stops.

If you don't understand, the first number means the starting number, the second number means for the ending number, and the third value is how much number is gonna skip from start to end.

Fact: If the for loop is at 3.00 and the end's requirement is 3.01, if your third number value is below end's requirement than the index (number), it stops. For example it skips 1 everytime and the index is at 3, the requirement is 3.5, it stops.

And how to match an string value together (and locate the Instance) is like this:

if game["Work" .. "space"] then
	print("Work" .. "space exists!")
end

The estimated output should be:

Workspace exists!

So .Instance means for it's children (commonly), and 2 dots means to match them together (String value).

After you learning both of these, combine them together. So your script should look like this:

local debounce = true
local Sound = script.Parent.Parent.Parent.taw.Sound
local Light = script.Parent.Parent.Parent.taw.Light
local Particle1 = script.Parent.Parent.Parent.taw.Particle1
local Particle2 = script.Parent.Parent.Parent.taw.Particle2

script.Parent.MouseClick:Connect(function()
    local time1 = math.random (30,150) --IMPORTANT: This is how long between each shot
    local time2 = math.random(1,100) --This just picks when in that second it'll happen.

    wait (time1+time2/100)
    if debounce == true then
        debounce = false
        Sound:Play()
        Light.Enabled = true
	Particle1.Enabled = true
	Particle2.Enabled = true
	for number = 1,10,1 do
		script.Parent.Parent.Parent.taw["ParticleEmitter" .. number].Enabled = true
	end
        wait(0.1)
        Light.Enabled = false
	Particle1.Enabled = false
	Particle2.Enabled = false
	for number = 1,10,1 do
		script.Parent.Parent.Parent.taw["ParticleEmitter" .. number].Enabled = false
	end
        debounce = true
    end
end)

Beware that matching them does not have a dot in-between.

If this didn't work, tell me in the comments and the error code, and I'll try to help

1 comment

0

Thank you! It works, but only one of the taw's is affected. By the way, i have multiple "taws" in the same model. Basically im trying to make explosions happen in certain spots where "taw" is, and I want the randomizer script to happen to each of them.

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