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

Gui will follow remove function with 1 player but not 2 players?

Asked by
KenzaXI 166
9 years ago

Right so, the gui is meant to be removed when it for fills it's purpose, and it will remove BUT only when there is 1 player in the server, This is a localscript within a TextButton, The Gui gets clones to the lighting by a normal script which in my workspace. Thanks for your help. Gui Clone script:

game.Players.PlayerAdded:connect(function(player)
    game.Workspace.Map1.ScreenGui:Clone().Parent = game.StarterGui
end)

Gui script:

repeat wait() until game.Players.LocalPlayer
local i = script.Parent
local map = workspace.Map1.Stadium.sa
local gui = script.Parent.Parent.Parent
local tele1 = game.Workspace.Map1.Tele1
function onButtonClicked()
    local plr = game.Players.LocalPlayer
    local character = plr.Character
if (plr and character ~= nil) then
    character:MoveTo(map.Position)  
    tele1:Clone().Parent = plr.PlayerGui
    script.Parent.Parent.Parent:Destroy()
end
    end
i.MouseButton1Down:connect(onButtonClicked)


1 answer

Log in to vote
0
Answered by
woodengop 1134 Moderation Voter
9 years ago

You could save the players in a table or use the NumPlayers property.

-- usage of Tables

local PlayersOnline = {}

game.PlayersAdded:connect(function(player) -- player Argument
    table.insert(PlayersOnline,player)
    if #PlayersOnline < 2 then
        -- code
    end
end)

-- usage of NumPlayers

if game.Players.NumPlayers < 2 then
    -- code
end
0
I rarely use tables because I don't get how to use them, Can you help me use this table please? KenzaXI 166 — 9y
0
Like a walkthrough on how it works? woodengop 1134 — 9y
0
Yeah KenzaXI 166 — 9y
Ad

Answer this question