I have a button on inside a frame on StarterGui (game.StarterGui.Frame.Button) and when I press that button I want it to run a script which is located in Lightning (game.Lightning.Script), how should I make this script or how should it be?
local Button = script.Parent
Button.MouseButton1Down:Connect(function()
local Lighting = game:GetService("Lighting")
local Script = Ligthing:FindFirstChild("Script")
Script.Disabled = false --Make sure to disable the script in lighting!
end)
I’m not even certain that scripts run inside Lighting, I’d be surprised if they do.
It’d be best if you placed the Script in ServerScriptService
Your best approach here is to integrate a RemoteEvent creating a communication between a LocalScript inside your StarterGui and your Script.
The connected function to the MouseButton1Click should :FireServer() this RemoteEvent, then on the recieving end your Script can connect upon OnServerEvent of this RemoteEvent and run whatever’s needed.
For example:
--// LocalScript
local Button = script.Parent.Button
local Remote = game:GetService("ReplicatedStorage").RemoteEvent
Button.MouseButton1Click:Connect(function()
Remote:FireServer()
end)
--// Script
local Remote = game:GetService("ReplicatedStorage").RemoteEvent
Remote.OnServerEvent:Connect(function()
--// Code
end)