So I am trying to make an random map script and works. But I tried to use one GUI visible when is loading. I tried to use PlayerGui but doesn´t work
local MapsFolder = game:GetService("Lighting").Maps
local Maps = MapsFolder:GetChildren()
local RoundTime = script.RoundTime
local IntermissionTime = script.IntermissionTime
local PlayerGui = game:GetService("Players"):WaitForChild("PlayerGui")
while true do
local ChosenMap = Maps[math.random(1,#Maps)]
local MapClone = ChosenMap:Clone()
wait(IntermissionTime.Value)
PlayerGui.MenuGui.LoadingGui.Visible = true
wait(5)
PlayerGui.MenuGui.LoadingGui.Visible = false
MapClone.Parent = game.Workspace
MapClone:MakeJoints()
wait(RoundTime.Value)
MapClone:Destroy()
end
Script located in ServerScriptService.
If this is a server script, you can’t reference the Player that way
What you can instead do, is get every player using a for i, v in pairs loop and change every Player’s GUI to enable/disable the LoadingGui when called
local MapsFolder = game:GetService("Lighting").Maps
local Maps = MapsFolder:GetChildren()
local RoundTime = script.RoundTime
local IntermissionTime = script.IntermissionTime
local Loading = false
while true do
local ChosenMap = Maps[math.random(1,#Maps)]
local MapClone = ChosenMap:Clone()
wait(IntermissionTime.Value)
for _, Player in pairs(game.Players:GetPlayers()) do
Player.PlayerGui.MenuGui.LoadingGui.Visible = true
end
wait(5)
for _, Player in pairs(game.Players:GetPlayers()) do
Player.PlayerGui.MenuGui.LoadingGui.Visible = false
end
MapClone.Parent = game.Workspace
MapClone:MakeJoints()
wait(RoundTime.Value)
MapClone:Destroy()
end
1 Like
Thank you. I forgeted about one think (PlayerGui isn’t a child of the Players service)
1 Like