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

(Reposted) Why the Gui doesn't open again when a player close the Gui after touch a part?

Asked by 1 year ago

was experimenting that I want that when a player touch a part, The gui shows and it's shows again when a player touchs the part again. But the script that i have it's only close the gui and it's doesn't open anymore. "It's a teleportation Gui but i want that the gui shows repeatedly"

This is the script:

local Part = script.Parent
local Debounce = false

Part.Touched:Connect(function(hit)
    if Debounce == false then
        Debounce = true
        if hit.Parent:FindFirstChild("Humanoid") then
            local plr = game.Players:GetPlayerFromCharacter(hit.Parent).PlayerGui
            script.ScreenGui:Clone().Parent = plr -- replace "ScreenGui" with the name of your ScreenGui
        end
        wait(1)
        Debounce = false
    end
end)

Close teleport gui script:

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Visible = false
end)

3 answers

Log in to vote
0
Answered by 1 year ago

Now, I am talking about the script that you wrote below because it's more important. The issue is that the script.Parent.Parent.Visible = false refers that it will only do that action, try to use this script:

script.Parent.MouseButton1Click:Connect(function()
    if script.Parent.Parent.Visible == false then
      script.Parent.Parent.Visible = true
    else
      script.Parent.Parent.Visible = false
      end
end)

Explanation:

When you press the button, if the ScreenGUI or whatever it is isn't visible, it becomes visible, else, it's going to make it invisible if it's open.

I hope it helps and solves your problem.

0
It doesn't work yet Queen1234_XD -26 — 1y
Ad
Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
1 year ago

try this:

local Part = script.Parent
local Debounce = false

Part.Touched:Connect(function(hit)
    if Debounce == false then
        Debounce = true
        if hit.Parent:FindFirstChild("Humanoid") then
            local plr = game.Players:GetPlayerFromCharacter(hit.Parent) -- make sure this IS a player thats touched us!..
            if(plr ~= nil) then
                --// we have a player, Woot!
                local PlayerGui = plr.PlayerGui

                local Gui = PlayerGui:FindFirstChild(script.ScreenGui.Name) 
                --// Check to see if this player has our gui already, if not then clone/give it!...
                if(Gui == nil) then
                    Gui = script.ScreenGui:Clone()
                    Gui.Parent = PlayerGui -- replace "ScreenGui" with the name of your ScreenGui
                end
                --// no matter what we show the gui!
                Gui.Visible = true
            end
        end
        wait(1)
        Debounce = false
    end
end)

I've just added a few checks to make sure the script doesn't crash and burn if a non player touches your touch brick/part. You don't need to change your Close teleport gui script as the above script re-shows your Gui if it finds it in the player. If it doesn't find the Gui in the PlayerGui it will clone it!.

Hope this helps! :)

0
Aww, But it's worked with a gui that i've had in my inv, I'll try to take in count. Tysm! Queen1234_XD -26 — 1y
Log in to vote
-1
Answered by 1 year ago

**Because u parent the gui to the player not the player gui.

on line 9 replace the code with this.**

 script.ScreenGui:Clone().Parent = plr.PlayerGui -- replace "ScreenGui" with the name of your ScreenGui

Hope this helps!

0
Their 'plr' variable is already referring to the PlayerGui. xInfinityBear 1777 — 1y
0
It doesn't work too Queen1234_XD -26 — 1y

Answer this question