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.
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.
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
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.
Thanks in advance. Definetly gonna use this information :)
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
With BindableEvents you can communicate between server scripts.
Thank you so much for the help.
np