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

Why does GUI immediately disappear after character reset?

Asked by 1 year ago

Problem: I have a round system which updates the gui text with a for loop. It works fine, but upon resetting, the gui disappears. I have set the ResetOnSpawn property of every gui I have in my game to false, and it doesn't seem to make a change. I do not have any errors on my console.

Goal: To have guis remain present even if a player resets.

Code:

local replicatedStorage = game:GetService("ReplicatedStorage")
local Events = replicatedStorage.Events
local RoundEvent = Events.RoundEvent
local VoteFunction = Events.VoteFunction
local players = game:GetService("Players")
local player = script:FindFirstAncestorWhichIsA("Player")
local randomMap = require(replicatedStorage:WaitForChild("Modules"):WaitForChild("RandomMap"))
local RoundGui = player.PlayerGui:WaitForChild("RoundGui")
local VotingGui = player.PlayerGui:WaitForChild("VotingGui")
local StatusLabel = RoundGui:WaitForChild("StatusText")
local Map1Image = VotingGui:WaitForChild("Map1Image")
local Map2Image = VotingGui:WaitForChild("Map2Image")
local Map3Image = VotingGui:WaitForChild("Map3Image")
local VB1 = Map1Image:WaitForChild("VoteButton")
local VB2 = Map2Image:WaitForChild("VoteButton")
local VB3 = Map3Image:WaitForChild("VoteButton")

local intermissionTime = 1
local mapVotingTime = 15

RoundEvent.OnClientEvent:Connect(function(enoughPlayers, minimumPlayerAmount, playerAmount)
    if enoughPlayers then
        while enoughPlayers do
            --Intermission
            for i = intermissionTime, 1, -1 do
                StatusLabel.Text = "Intermission: "..i
                wait(1)
            end
            --Map Voting
            VotingGui.Enabled = true


            local Map1, Map2, Map3 = randomMap.getRandomMaps()

            Map1Image.Image = Map1.VotingImage
            Map2Image.Image = Map2.VotingImage
            Map3Image.Image = Map3.VotingImage
            Map1Image.MapName.Text = Map1.Name
            Map2Image.MapName.Text = Map2.Name
            Map3Image.MapName.Text = Map3.Name

            for _, gui in ipairs(VotingGui:GetDescendants()) do
                if gui:IsA("TextButton") and string.match(gui.Name, "VoteButton") then
                    print(gui)
                    local mapImageName = string.match(gui.Parent.Name, "Map%d+Image")
                    local mapName = gui.Parent.MapName.Text
                    local mapNumber = string.match(mapImageName, "%d+")
                    local mapVoteName = "Map"..mapNumber.."Votes"
                    gui.Activated:Connect(function()
                        print("pressed")
                        for _, player in ipairs(players:GetPlayers()) do
                            local mapImage = player.PlayerGui.VotingGui:FindFirstChild(mapImageName)
                            local Votes = mapImage.Votes

                            local VoteAmount = VoteFunction:InvokeServer(mapVoteName)

                            print(VoteAmount)

                            Votes.Text = "Votes: "..VoteAmount

                        end
                    end)
                end
            end

            for i = mapVotingTime, 1, -1 do
                StatusLabel.Text = "Map Voting: "..i
                wait(1)
            end

        end
    else
        local playersNeeded = minimumPlayerAmount - playerAmount
        if playersNeeded == 1 then
            local StatusLabel = player:WaitForChild("PlayerGui"):WaitForChild("RoundGui"):WaitForChild("StatusText")
            StatusLabel.Text = "Not enough players to start a round. "..playersNeeded.." more player needed."
        else
            local StatusLabel = player:WaitForChild("PlayerGui"):WaitForChild("RoundGui"):WaitForChild("StatusText")
            StatusLabel.Text = "Not enough players to start a round. "..playersNeeded.." more players needed."
        end
    end
end)

Extra Information: I noticed that the voting gui show after a couple of seconds, but the gui that displays the time for intermission doesn't show.

Conclusion: As always, thank you for taking the time to read this, and I hope this issue can eventually be resolved. - Bloxyses

Answer this question