Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Is my scripting right on this and will it work?

Asked by 9 years ago

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


1 answer

Log in to vote
1
Answered by
u_g 90
9 years ago

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)

Ad

Answer this question