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

How to execute another script from a script?

How do you run a script using another script?

For example:

I have two scripts. One script is in the TextButton and when the player clicks it, it runs another script that is in the Workspace.

2 answers

✓ Accepted answer

Use a BindableEvent.

Script in button:

script.Parent.MouseButton1Click:Connect(function()
	workspace.Script.BindableEvent:Fire() --BindableEvent inside the script in workspace
end)

Script in workspace:

local be = script:WaitForChild("BindableEvent")
be.Event:Connect(function()
	print("Button clicked")
end)

--Output: Button clicked

3 comments

0

With BindableEvents you can communicate between server scripts.

0

Thank you so much for the help.

0

np

You could look into remote events if the script inside the TextButton is a localscript.

You also could look into module scripts.

You also could disable the script you want to run in Workspace and then enable it when the player clicks the button.

I would recommend always using a local script when dealing with on click events like TextButtons. Then if you want the server to do something, use remote events to send the information that the button was clicked from the local script in textButton.

There's a thing called Client and Server.

1 comment

0

Thanks in advance. Definetly gonna use this information :)

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