#Joining 2 scripts

1 messages · Page 1 of 1 (latest)

eternal aurora
#

Hello! I want to join the ButtonScript to the Event1 script together but I don't know how can I do it and with what.
Please help me

--ButtonScript
local clickDetector = script.Parent
local button = game.Workspace.Button
local debounce = false

clickDetector.MouseClick:Connect(function()
    if debounce then return end
    debounce = true
    print("Part clicked")

    task.wait(2)

    debounce = false
end)```

```lua
--Event1
for i = 1, 100 do
    local part = game.Workspace.KillPart:Clone()
    part.Anchored = false
    part.Position = Vector3.new(
        math.random(-256, 256), -- Xposition
        math.random(50, 150),   -- Yposition
        math.random(-256, 256)  -- Zposition
    )
    part.Parent = workspace
end```
hard pine
#

Put the event1 inside the click detector event function

eternal aurora
#

and to randomize the events too

hard pine
#

I don't understand

eternal aurora
#

When I click the button, a random event start, Event1 is the First event within all of the events and I don't want the Button Scripts to be a mess and I want a script to be called in another script so I can use it

hard pine
#

Create a function for each event and create a table and put all event inside the table

eternal aurora
#

in the same script ?

hard pine
#

Yeah

eternal aurora
#

Imma try it I never done tables

hard pine
#

You can read roblox docs on them

#

And watch tutorials on YouTube

eternal aurora
#

lemme look for it

gusty bough
hard pine
eternal aurora
#

maybe for the script to look cleaner

hard pine
#

Yeah why not

eternal aurora
#

I never tested module script I'm gonna try it too

#

Thanks guys

gusty bough
hard pine
eternal aurora
#

At least 20 events for me

hard pine
#

Then you gonna use module scripts lol

eternal aurora
#

yea

gusty bough
hard pine
#

So module scripts are not only to reuse scripts but also to keep the script readable

eternal aurora
#

I think I got it

gusty bough
# eternal aurora I don't understand why isn't it working

So you correctly required the module but you made 2 mistakes:

1, you're trying to call the module instead of calling a function inside the module
2. So the "Event1" function is inside the module, but only accessible from inside of it. Add it to he module table

eternal aurora
gusty bough
#

Well yes, yet you can add some logic to just call a random event

eternal aurora
#

I don't understand

#

so I can't require the Events but I need to require one event at a time

gusty bough
#

If I roughly see what you're doing then


Events["Event"..math.random(1, AMOUNT_OF_EVENTS)]()
gusty bough
#

Yet you've to call function inside the module, not the entire module

eternal aurora
#

huh

unkempt kayakBOT
#

studio** You are now Level 15! **studio

gusty bough
#

So:

local Events = {}

function Events.Event1() 
  --blabla
end

return Events


---------------
local Events = require(...)

Events.Event1()
eternal aurora
#

ohhhh

#

I think I'm just stupid but its doing an error

gusty bough
#

Also, please don't store scripts inside the workspace, please just put them in serverscriptservice. It's easier to keep track of scripts, and just safer (e.g., if a model gets deleted with a script inside of it, then that script will also be removed. Unachored models can also be flung into the void, which will also cause them to be delted)

gusty bough
eternal aurora
eternal aurora
gusty bough
#

Tell me what difference you see

eternal aurora
#

oh ok I can't use a local

#

and now I need to randomize it with other events but I still don't know how to do it lol

eternal aurora
gusty bough
#

That's how you can call a random event based on your current naming scheme. Just fill the amount of events in in... well, AMOUNT_OF_EVENTS

eternal aurora
#

or just lua math.random

gusty bough
#

no...

#

still, no

#

Just exactly what I typed

eternal aurora
#

I didn't say the full parts I know I need to do it

#

but is the "Event" before math.random useful ?

gusty bough
eternal aurora
#

U helped me alot

eternal aurora