Normally, when you have objects, you check if they have something by just use [] or .:
if string.sub then
end
if string["sub"] ~= nil then
end
if not string.sub == nil then
end
However, for ROBLOX objects, if the object isn't there, you will get an error, not nil.
On a ROBLOX object, instead use :FindFirstChild:
if workspace:FindFirstChild("BlueTaslem") then
end
Nonetheless, Instead of applying this, just fix your script! Don't cover up problems, solve them! That code shouldn't be happening over and over -- that is the problem.
First: checking if z == 1 isn't the wise way to do it. Instead, just put that code after the loop -- what you mean by if z == 1 is that the loop is done, so use that fact!
The only issue is MapName -- which you'll just add another short loop to do. However, this is not the best way to structure this, and, for instance, won't work with FilteringEnabled.
function intermission()
for time = 45,1, -1 do
wait(1)
for _, player in pairs(game.Players:GetPlayers()) do
local GUI1 = player.PlayerGui.Intermission.Frame
local GUI2 = player.PlayerGui.NewsBar.Frame
local Time = GUI1.Seconds
GUI1.Visible = true
GUI2.Visible = true
Time.Text = time
end
num = 2
maps = {"Abandoned Church", "Campsite", "Facility"}
m = math.random(1, num)
t = game.Lighting:FindFirstChild(maps[m]):clone()
t.Parent = game.Workspace
t:MakeJoints()
for _, player in pairs(game.Players:GetPlayers()) do
local MapName = player.PlayerGui.StartRound.Frame.Map
local GUI3 = GUI1.Title
GUI3.Text = "Loading Map..."
Time.Text = " "
MapName.Text = t.Name
end
wait(7)
TeleportToMap()
end
end
A more correct way to manage GUIs would be something like this:
local player = game.Players.LocalPlayer
local gui = player:WaitForChild("PlayerGui")
local intermissionFrame = gui.Intermission.Frame
local newsBar = gui.NewsBar.Frame
local globalMessage = game.ReplicatedStorage.Status
local globalInt = game.ReplicatedStorage.InIntermission
function update()
local msg = globalMessage.Value
if globalInt.Value then
newsBar.Visible = true
intermissionFrame.Visible = true;
intermissionFrame.Seconds.Text = msg
else
intermissionFrame.Visible = false
newsBar.Visible = false
intermissionFrame.Visible = false
gui.StartRound.Frame.Map.Text = msg
end
end
globalMessage.Changed:connect(update)
globalInt.Changed:connect(update)
update()
Our game round manager is now much simpler:
function intermission()
for time = 45,1, -1 do
wait(1)
game.ReplicatedStorage.InIntermission.Value = true
game.ReplicatedStorage.Status.Value = time
end
local maps = {"Abandoned Church", "Campsite", "Facility"}
local m = math.random(1, #maps)
local t = game.Lighting:FindFirstChild(maps[m]):Clone()
t.Parent = game.Workspace
t:MakeJoints()
game.ReplicatedStorage.InIntermission.Value = false
game.ReplicatedStorage.Status.Value = "Loading Map..."
wait(7)
TeleportToMap()
end
where InIntermission is a BoolValue in ReplicatedStorage and Status is a StringValue in ReplicatedStorage.
1 comment
Please accept the answer! (It gives both of us reputation. You need reputation because if you have like -30 reputation you can get banned)