I have a script which turns lights on and off but it only does it locally (for the player that presses the TextButton. I am wondering how I can use remote events and server scripts to make the change for the whole server and not just the local player.
--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Variables
local RemoteEvent = ReplicatedStorage.RemoteEvent
local Button = script.Parent
--//Functions
Button.MouseButton1Click:Connect(function()
RemoteEvent:FireServer() --//Fires the event
end)
ServerScript:
--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Variables
local RemoteEvent = ReplicatedStorage.RemoteEvent
local Light = workspace.Part.PointLight --//Reference your light
--//Functions
RemoteEvent.OnServerEvent:Connect(function(player) --//The player argument is passed in automatically
--//Makes the lights brightness to 100
Light.Brightness = 100
--//OR you can enable the light
Light.Enabled = true
end)
So if you want to change something for the whole server then you need to put remote event to ReplicatedStorage.
After this put a local script for example to StarterGui:
local change = "change for whole server"
wait()
game.ReplicatedStorage.RemoteEvent:FireServer(change)
Now you have done first step, you gave info to your remove event. Now remote event needs to collect it correctly, so put a script (not local script) for example to StarterGui.
Thanks for both of your solutions, I have marked @Katrist’s as the solution as it was posted first but thanks @FrozenTheCreator as well for your reply.
if room == "Exhibit" then
local exhibitRoom = script.Parent.Parent.ExhibitRoom.Text
exhibitEvent:FireServer(exhibitRoom)
end
game.ReplicatedStorage:FindFirstChild("").OnServerEvent:Connect(function(exhibitRoom)
-- Do whatever with the exhibitRoom variable! It will have sent the text to the server.
end)