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

How to automatically close gui after 4 seconds?!

Asked by 3 years ago

Im making a murder mystery type game and i have guis to display the role of the player when the round starts. The game is locked in first person so i cant add a button and i want it to automatically close after 4 seconds. however, everything i try wont work. here is my code:

01local killerWeapon = game.ServerStorage.Knife
02local plrs = game.Players
03local inRound = game.ReplicatedStorage.inRound
04 
05local survivors = {}
06 
07 
08inRound.Changed:Connect(function()
09    if inRound.Value == true then
10        local chosen = plrs:GetChildren()[math.random(1, #plrs:GetChildren())] 
11 
12        chosen.PlayerGui.Picker.Background.RoleGiven.Text = "Murderer"
13        chosen.PlayerGui.Picker.Background.RoleGiven.TextColor3 = Color3.fromRGB(255, 0, 0)
14 
15        chosen.PlayerGui.Picker.Background.Visible = true
View all 39 lines...

2 answers

Log in to vote
1
Answered by 3 years ago

When looping through players, consider adding a coroutine if you're waiting for a specific period of time.

A coroutine creates a new thread & allows the environment to continue running without yielding; this is what we call Multithreading.

01local PlayersService = game:GetService("Players")
02local ReplicatedStorage = game:GetService("ReplicatedStorage")
03local ServerStorage = game:GetService("ServerStorage")
04 
05local BoolValue = ReplicatedStorage:WaitForChild("inRound")
06local Knife = ServerStorage:WaitForChild("Knife")
07local Survivors = {}
08 
09ReplicatedStorage:WaitForChild("inRound").Changed:Connect(function(property)
10    if tostring(property) == "Value" then
11        local inRound = BoolValue.Value
12        if inRound == true then
13            local Chosen = PlayersService:GetPlayers()[math.random(1, #PlayersService:GetPlayers())]
14            local PlayerGui = Chosen:FindFirstChildWhichIsA("PlayerGui") or Chosen:WaitForChild("PlayerGui")
15 
View all 59 lines...
0
I tried this code but the gui didnt appear. I also put some prints in but they didnt work either. YourAverageMyth 45 — 3y
0
because you suck at scripting ez ez ez ez pingsock 111 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Just add a wait()...??

1-- between lines 37 and 38 maybe
2wait(4)
3for i, plr in pairs(plrs:GetChildren()) do
4    plr.PlayerGui.Picker.Background.Visible = false
5end
0
adding a wait causes 1 player to see the survivor role, then when it dissapears the next person sees the survivor role. YourAverageMyth 45 — 3y
0
Sorry for the late reply, but i thought if you add it outside the loops like i said maybe between lines 37 and 38, it would again go through every player and instead of adding the role and making it visible, it just makes the role not visible? Omq_ItzJasmin 666 — 3y

Answer this question