Here I have a very simple script to make doors lock with a press of a button, and the text changes when that button is pressed.
local Button = script.Parent
local DoorLocked = false
Button.MouseButton1Click:Connect(function()
if not DoorLocked then
DoorLocked = true
game.Workspace.Door.Script.Disabled = true
Button.Text = "Doors Locked"
else
DoorLocked = false
game.Workspace.Door.Script.Disabled = false
Button.Text = "Doors Open"
end
end)
The script is inside the button (as you can tell by the local Button variable).
And I was wondering, how could I make it so the text changes for everyone in the server, and not just for the client (I think I’m saying that right)? Thank you so much!
You can fire a remote event to all players using RemoteEvent:FireAllClients(args)
On the client you would handle this with a RemoteEvent.OnClientEvent connection
A remote event is one way to send information between the client and server. Here is a full tutorial on them.
Client to server example:
local remote = game.ReplicatedStorage["Remote Name"]
--// Client
remote:FireServer("hello!")
--// Server
remote.OnServerEvent:Connect(function(player, argument)
print(player.Name .. " says " .. message)
end)
--// Output on the server
Synthetic_Flame says hello!
Server to client example:
local remote = game.ReplicatedStorage["Remote Name"]
--// Server
remote:FireClient(game.Players.Synthetic_Flame, "Hello from the server!")
--// Client
remote.OnClientEvent:Connect(function(message)
print("The server says: " .. message)
end)
--// Output from the client
The server says: Hello from the server!
--//Button-Script
local Button = script.Parent
local DoorLocked = false
local ReplicatedStorage = game:GetService("ReplicatedStorage")
Button.MouseButton1Click:Connect(function()
ReplicatedStorage.DoorLock:FireServer(DoorLocked)
DoorLocked = not DoorLocked
end)
--//Server-Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.DoorLock.OnServerEvent:Connect(function(Player, DoorLocked)
if workspace:FindFirstChild(Player.Name.."'s Door") then
local Door = workspace:WaitForChild(Player.Name.."'s Door")
Door.Script.Disabled = not DoorLocked
end
end)
why would you need to change the buttons text on the server if its a playergui it wouldent replicate to anyone else anyways