Your issue here lies within the scope of the function it's a very simple fix!
function findgui()
for i, v in pairs(game.Players:GetPlayers()) do
local gui = v.PlayerGui:FindFirstChild("ScreenGui").TextBox
end
end
while wait() do
gui = findgui()
if game.Players.NumPlayers >= 2 then
gui.Text = "Starting the Fight."
else
gui.Text = "Waiting for 2 or more players."
wait()
end
end
You will want to tear the local gui variable out of the function so it can be read by the entire script as such.
local gui = v.PlayerGui:FindFirstChild("ScreenGui").TextBox
function findgui()
for i, v in pairs(game.Players:GetPlayers()) do
end
end
while wait() do
gui = findgui()
if game.Players.NumPlayers >= 2 then
gui.Text = "Starting the Fight."
else
gui.Text = "Waiting for 2 or more players."
wait()
end
end
But looking at this script, the scope isn't the only issue. If this is in a local script, the for i,v in pairs
loops is unnecessary because you can call the local player directly.
If this is in a server script, it won't work period because only local scripts can write to the PlayerGui, in which case you will need close to a full re-write.
If you have any other questions feel free to Roblox PM me or ask in the comments!
~MBacon15
1 comment
The answers down below are pretty much what I just said :/