Why won't GUI destroy when one value or the other becomes false?
Asked by
5 years ago Edited 5 years ago
So I have this script that makes it when two values are true meaning that two players are touching two separate blocks (Thanks to SerpentineKing), the function finds the two players hitting the block and adds a GUI into their PlayerGUI. I am now trying to make it so when one of the people aren't touching one of the two blocks anymore, meaning one of the values become false, the GUI is destroyed from both player's PlayerGUI, and then this script will work when both players touch the two blocks again.
01 | local model = script.Parent |
02 | local connect 1 = model:WaitForChild( "JoinBlock1" ) |
03 | local connect 2 = model:WaitForChild( "JoinBlock2" ) |
04 | local full 1 = connect 1 :WaitForChild( "Full" ) |
05 | local full 2 = connect 2 :WaitForChild( "Full" ) |
07 | local ss = game:GetService( "ServerStorage" ) |
08 | local start 1 = ss:WaitForChild( "Start1" ) |
09 | local start 2 = ss:WaitForChild( "Start2" ) |
14 | local function CheckConnection() |
15 | if player 1 and player 2 and player 1 ~ = player 2 and full 1. Value = = true and full 2. Value = = true then |
16 | local pgui 1 = player 1 :WaitForChild( "PlayerGui" ) |
17 | local pgui 2 = player 2 :WaitForChild( "PlayerGui" ) |
19 | if not pgui 1 :FindFirstChild( "Start1" ) then |
20 | local clone 1 = start 1 :Clone() |
24 | if not pgui 2 :FindFirstChild( "Start2" ) then |
25 | local clone 2 = start 2 :Clone() |
31 | local function CheckConnectionEnded() |
32 | if player 1 and player 2 and player 1 ~ = player 2 and full 1. Value = = false or full 2. Value = = false then |
33 | local pgui 1 = player 1 :WaitForChild( "PlayerGui" ) |
34 | local pgui 2 = player 2 :WaitForChild( "PlayerGui" ) |
36 | if pgui 1 :FindFirstChild( "Start1" ) then |
40 | if pgui 2 :FindFirstChild( "Start2" ) then |
46 | connect 1. Touched:Connect( function (hit) |
47 | player 1 = game:GetService( "Players" ):GetPlayerFromCharacter(hit.parent) |
51 | connect 2. Touched:Connect( function (hit) |
52 | player 2 = game:GetService( "Players" ):GetPlayerFromCharacter(hit.parent) |
56 | connect 1. TouchEnded:Connect( function (ended) |
57 | player 1 = game:GetService( "Players" ):GetPlayerFromCharacter(ended.parent) |
58 | CheckConnectionEnded() |
61 | connect 2. TouchEnded:Connect( function (ended) |
62 | player 2 = game:GetService( "Players" ):GetPlayerFromCharacter(ended.parent) |
63 | CheckConnectionEnded() |