Hello, I am making a simple script where a remote event fire on the server to all players to change their status in a GUI.
The problem is, my script prints the ‘1’, therefore firing the remote, but on the client side script nothing happens, as seen here:
local status = game.ReplicatedStorage.Variables.Status
-- remotes for schedule (sloppy)
local folder = game.ReplicatedStorage.Remotes.ScheduleRemotes
local staff1 = folder.StatusChangeStaff
local staff2 = folder.StatusChangeStaff2
local staff3 = folder.StatusChangeStaff3
local staff4 = folder.StatusChangeStaff4
while true do
staff1:FireAllClients()
print("1")
wait(120)
staff2:FireAllClients()
wait(120)
staff3:FireAllClients()
wait(120)
staff4:FireAllClients()
wait(120)
end
local Replicated = game:GetService("ReplicatedStorage")
local Remotes = Replicated:WaitForChild("Remotes")
local ScheduleRemotes = Remotes:WaitForChild("ScheduleRemotes")
local StatusChangeStaff = ScheduleRemotes:WaitForChild("StatusChangeStaff")
local STATUS = Replicated:WaitForChild("Variables"):WaitForChild("Status")
Other than that, I’d like to see the rest of your client side [ relevant to the code]
local plr = game.Players.LocalPlayer
local players = game:GetService("Players")
local teams = game:GetService("Teams")
local Replicated = game:GetService("ReplicatedStorage")
local Remotes = Replicated:WaitForChild("Remotes")
local ScheduleRemotes = Remotes:WaitForChild("ScheduleRemotes")
local StatusChangeStaff = ScheduleRemotes:WaitForChild("StatusChangeStaff")
local status = Replicated:WaitForChild("Variables"):WaitForChild("Status")
game.ReplicatedStorage.Remotes.ScheduleRemotes.StatusChangeStaff.OnClientEvent:Connect(function()
status.Value = "Breakfast"
print("fired")
end)
game.ReplicatedStorage.Remotes.ScheduleRemotes.StatusChangeStaff2.OnClientEvent:Connect(function()
if plr.Team == teams["Test Subject"] then
status.Value = "Free Time"
elseif plr.Team == teams["Administrative Personnel"] or plr.Team == teams["Bureau of Intelligence"] or plr.Team == teams["Department of Research"] or plr.Team == teams["Facility Personnel"] or plr.Team == teams["Maintenance Department"] or plr.Team == teams["Office of Public Enforcement"] or plr.Team == teams["Security Corps"] then
status.Value = "Office Hours"
end
end)
game.ReplicatedStorage.Remotes.ScheduleRemotes.StatusChangeStaff3.OnClientEvent:Connect(function()
status.Value = "Dinner"
end)
game.ReplicatedStorage.Remotes.ScheduleRemotes.StatusChangeStaff4.OnClientEvent:Connect(function()
if plr.Team == teams["Test Subject"] then
status.Value = "Cell Time"
elseif plr.Team == teams["Administrative Personnel"] or plr.Team == teams["Bureau of Intelligence"] or plr.Team == teams["Department of Research"] or plr.Team == teams["Facility Personnel"] or plr.Team == teams["Maintenance Department"] or plr.Team == teams["Office of Public Enforcement"] or plr.Team == teams["Security Corps"] then
status.Value = "Rest"
end
end)
--//Services
local players = game:GetService("Players")
local teams = game:GetService("Teams")
local Replicated = game:GetService("ReplicatedStorage")
--//Variables
local Remotes = Replicated:WaitForChild("Remotes")
local ScheduleRemotes = Remotes:WaitForChild("ScheduleRemotes")
local STATUS = Replicated:WaitForChild("Variables"):WaitForChild("Status")
local plr = players.LocalPlayer
--//Events
ScheduleRemotes:WaitForChild("StatusChangeStaff").OnClientEvent:Connect(function()
STATUS.Value = "Breakfast"
print("fired")
end)
ScheduleRemotes:WaitForChild("StatusChangeStaff2").OnClientEvent:Connect(function()
if plr.Team == teams["Test Subject"] then
STATUS.Value = "Free Time"
elseif plr.Team == teams["Administrative Personnel"] or plr.Team == teams["Bureau of Intelligence"] or plr.Team == teams["Department of Research"] or plr.Team == teams["Facility Personnel"] or plr.Team == teams["Maintenance Department"] or plr.Team == teams["Office of Public Enforcement"] or plr.Team == teams["Security Corps"] then
STATUS.Value = "Office Hours"
end
end)
ScheduleRemotes:WaitForChild("StatusChangeStaff3").OnClientEvent:Connect(function()
STATUS.Value = "Dinner"
end)
ScheduleRemotes:WaitForChild("StatusChangeStaff4").OnClientEvent:Connect(function()
if plr.Team == teams["Test Subject"] then
STATUS.Value = "Cell Time"
elseif plr.Team == teams["Administrative Personnel"] or plr.Team == teams["Bureau of Intelligence"] or plr.Team == teams["Department of Research"] or plr.Team == teams["Facility Personnel"] or plr.Team == teams["Maintenance Department"] or plr.Team == teams["Office of Public Enforcement"] or plr.Team == teams["Security Corps"] then
STATUS.Value = "Rest"
end
end)
Now, this is more readable and more tidy.
Now may I ask you,
What type of value is STATUS? [String,Number,Bool,etc…]
What about other events?
3)You shoul work with task.wait rather than with wait.
Your problem is most likely that :FireAllClients() is run before the player is added to the game.
Try this:
local status = game.ReplicatedStorage.Variables.Status
local players = game:GetService("Players")
-- remotes for schedule (sloppy)
local folder = game.ReplicatedStorage.Remotes.ScheduleRemotes
local staff1 = folder.StatusChangeStaff
local staff2 = folder.StatusChangeStaff2
local staff3 = folder.StatusChangeStaff3
local staff4 = folder.StatusChangeStaff4
players.PlayerAdded:Connect(function(player)
while true do
staff1:FireAllClients()
print("1")
wait(120)
staff2:FireAllClients()
wait(120)
staff3:FireAllClients()
wait(120)
staff4:FireAllClients()
wait(120)
end
end)