Call a function from a server script from another server script

Yes yes, I’m lazy. I can’t be bothered to do a module script :yum:

Anyway, I have any function like so in a server script:

local function yes()

print("No")

end

ClickDetector.MouseClick:Connect(yes)

Then in another server script, I want to call function “yes” (while also sending 3 parameters as well)
How can I do this without wasting lots of my time by making the first one a module script?

1 Like

Making a module script isn’t that time consuming though, well to answer your question you can use a global variable to make the function global

1 Like

How does that work?

zzzzzzzzzzzzzzz30chars

You can use a BindableFunction (or BindableEvent if you aren’t expecting any return values).

Main script:

local function yes()
    print('No')
end

game.ServerStorage.BindableEvent.Event:Connect(yes)

Script 2:

game.ServerStorage.BindableEvent:Fire()
1 Like

I think just remove the local

function yes()

print("No")

end

ClickDetector.MouseClick:Connect(yes)
1 Like
_G.aFunc = function(txt)
print(txt)
end

Some other script

_G.aFunc("Egg")

Result
prints Egg

This can also be used to store variables, though I would still suggest using modules as it makes things cleaner and easier to work with

1 Like

This works, thanks! I will probably swap to ModuleScript in the future, just trying to get all of the basics of the game down first then will optimize more.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.