Yeah, it is in workspace. What about it? That line causes no problems for me.
You need the server to run that line.
The server is running that line. The code displayed in the post is running on a ServerScript
I’m saying that it’s necessary to send remote events to the server.
Okay so instead of :Move()-ing the character on the Server, I now do that on the client, and it’s fixed some things and broken some others. I disable the Spectate script via the server. The voting procedure still needs to happen three times for things to start breaking, but on the third time, it fails to disable the Spectate script.
You should not be disabling a script in this scenario. Just send a signal from a RemoteEvent
that deactivates any active spectation and disables the GUI
Okay so you want the Server to tell the Client via RemoteEvent to disable the SpectateScript and the SpectateGuis?
local players = team:GetPlayers()
local enabledPlayers = {}
local remote = game:GetService("ReplicatedStorage").RemoteEvent
remote.OnServerEvent:Connect(function(player,enabled)
enabledPlayers[player.UserId] = enabled
end)
for i, v in players do
local gui = v:FindFirstChild("PlayerGui")
if gui then
if enabledPlayers[v.UserId] or enabledPlayers[v.UserId] == nil then --if spectating then
print("count increased")
count += 1
v.Character:MoveTo(workspace.SpectatorBrick.Position) --teleports player to a spectator hub so that they don't interfere with gameplay
end
end
end
if #players == count then --if all players are in spectator mode (the "Spectate" LocalScript in their PlayerGui is set to TRUE) then that means the whole lobby is DEAD.
print("all players dead")
workspace.VOTE_TOGGLE.Enabled = true --This enables a voting procedure, not important.
end
When you disable Spectate, fire the remote event to the server.
local remote = game:GetService("ReplicatedStorage")
remote:FireServer(false)
I’m having some difficulties implementing it, give me a few minutes to see if it works
Why are you searching for the player.UserId
’th element in the table? If my UserId is 12456 lets say- then wouldn’t it find the 12456th element in the table?
I’m setting the 123456th element of the table to true or false, I’m not searching for it.
It didn’t really fix the issue- let me send you the entire script.
local team = game.Teams["Green Hill"]
local count = 0 --dead count
local remote = game:GetService("ReplicatedStorage").Events.Spectate
while task.wait(2) do
local players = team:GetPlayers()
local enabledPlayers = {}
remote.OnServerEvent:Connect(function(player,enabled)
enabledPlayers[player.UserId] = enabled
end)
for i, v in players do
local gui = v:FindFirstChild("PlayerGui")
if gui then
if enabledPlayers[v.UserId] or enabledPlayers[v.UserId] == nil then --if spectating then
print("count increased")
count += 1
v.Character:MoveTo(workspace.SpectatorBrick.Position) --teleports player to a spectator hub so that they don't interfere with gameplay
end
end
end
if #players == count then --if all players are in spectator mode (the "Spectate" LocalScript in their PlayerGui is set to TRUE) then that means the whole lobby is DEAD.
print("all players dead")
workspace.VOTE_TOGGLE.Enabled = true --This enables a voting procedure, not important.
end
This is using your modification which I’ve probably applied incorrectly… This is the ServerScript in Workspace
game.ReplicatedStorage.Events.VotingEnded.OnClientEvent:Connect(function(map)
print("spectating OVER")
cam.CameraSubject = plr.Character
left.Visible = false
right.Visible = false
nameplate.Visible = false
local chr = game.Players.LocalPlayer.Character
chr:MoveTo(map.Value.Position)
script.Enabled = false
local remote = game.ReplicatedStorage.Events.Spectate
remote:FireServer(false)
end)
This is a block of code in the Spectate script (client-side) which fires after Voting Procedure is finished.
What’s happening now is that every 2 seconds the Voting Procedure begins. Also, I get teleported to the SpectatorBrick every 2 seconds. I’m never put in Spectator Mode (I’m always put in Spectator Mode after the Spectate script is enabled but I guess that isn’t happening here? I’m really lost)
Try this:
local team = game.Teams["Green Hill"]
local count = 0 --dead count
local remote = game:GetService("ReplicatedStorage").Events.Spectate
local enabledPlayers = {}
remote.OnServerEvent:Connect(function(player,enabled)
enabledPlayers[player.UserId] = enabled
end)
while task.wait(2) do
local players = team:GetPlayers()
for i, v in players do
local gui = v:FindFirstChild("PlayerGui")
if gui then
if enabledPlayers[v.UserId] or enabledPlayers[v.UserId] == nil then --if spectating then
print("count increased")
count += 1
v.Character:MoveTo(workspace.SpectatorBrick.Position) --teleports player to a spectator hub so that they don't interfere with gameplay
end
end
end
if #players == count then --if all players are in spectator mode (the "Spectate" LocalScript in their PlayerGui is set to TRUE) then that means the whole lobby is DEAD.
print("all players dead")
workspace.VOTE_TOGGLE.Enabled = true --This enables a voting procedure, not important.
end
I think if I modify this I can get it to work
The Spectate still doesn’t appear at all though… I’ll try this again tomorrow. Thanks for the help