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

Gui and hint not working right?

Asked by
Spoookd 32
8 years ago

I am getting a gui to come up when a map is chosen and the players are about to be teleported. Everything works except for the gui and the hint that comes up when there is less than 2 people in the game. The players teleport to the map after a couple of seconds and the gui doesnt come up at all still. Then the second player in the server gets the gui after they teleport, but both get the "You need more than 2 players to play" hint. The server script is in ServerScriptStorage.

local mapInstantiated = false
maps = game.ReplicatedStorage:GetChildren()

game.Players.PlayerAdded:connect(function (player) --fired whenever a player joins
    if game.Players.NumPlayers >= 2 and mapInstantiated ~= true then --check whether there are enough players and also whether a map has been instantiated
        for i, v in pairs(game.Workspace:GetChildren()) do
            if v:IsA('Hint') then
                v:Destroy()
            end
        end
        ranmap = math.random(1, #maps)
        wait(1)
        chosen = maps[ranmap]
        chosenclone = chosen:Clone()
        chosenclone.Parent = game.Workspace
        if chosenclone.Parent == game.Workspace then
            player.PlayerGui.ScreenGui.Frame.Visible = true
            player.PlayerGui.ScreenGui.Frame.Map.Visible = true
            player.PlayerGui.ScreenGui.Frame.Madeby.Visible = true
            player.PlayerGui.ScreenGui.Frame.MapName.Visible = true
        end
        wait(5)
        spawn = chosenclone.SpawnPoint
        wait(5)
        for i,v in pairs(game.Players:GetPlayers()) do
            name = v.Name
            check = v.Character
            if check then
                checkHumanoid = check:FindFirstChild("Humanoid")
                if checkHumanoid then
                    check:MoveTo(spawn.Position)
                end
            end
        end
    if not(game.Workspace:findFirstChild("Hint")) then  -- If a hint is not a child of the workspace
            h = Instance.new("Hint", game.Workspace)
            h.Text = "You need more than 1 player to play."
    end
        mapInstantiated = true
    end
end)

0
findFirstChild() is depreciated, use FindFirstChild() instead (I highly doubt this is the issue though, ROBLOX usually just goes with it.) The_Sink 77 — 8y

Answer this question