I want to make sure all my scripting is right. I am trying to make this so if the max players are online spawn the becon but if they are not delete it.
if game.Players.MaxPlayers:connect(function(player) == true do local c = game.ServerStorage.Becon:Clone() c.Parent = game.Workspace c.Position = Vector3.new(42,0.5,-25) end) else end if game.workspace.Becon do if game.Players.MaxPlayers:connect(function(player) ~= do game.workspace.Becon:Destroy() end end
The if statements are not correctly used, and the event is not valid. Try this one, instead:
game.Players.ChildAdded:connect(function(player) -- This will connect every time a player is added local numberofPlayers = game.Players:GetChildren() numberofPlayers = #numberofPlayers if game.Players.MaxPlayers == numberofPlayers then local c = game.ServerStorage.Becon:clone() c.Parent = game.Workspace c.Position = Vector3.new(42,0.5,-25) end end) game.Players.ChildRemoved:connect(function(player) -- This'll connect every time a player is removed local numberofPlayers = game.Players:GetChildren() numberofPlayers = #numberofPlayers if game.Players.MaxPlayers ~= numberofPlayers then if game.Workspace:findFirstChild("Becon") ~= nil then game.Workspace.Becon:Destroy() end end end)