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

How do i make it so that when you step on a part only 1 GUI can show up?

Asked by 6 years ago

so say for example you step on a part. You get a GUI that shows up on your screen. But when i tried to do it multiple showed up.

1script.Parent.Touched:Connect(function(player)
2    local player = game.Players:GetPlayerFromCharacter(player.Parent)
3    local shop = game.ServerStorage.ScreenGui:Clone()
4    shop.Parent = player:WaitForChild("PlayerGui")
5-- below here i got no idea what to do
6end)

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You would check if the ScreenGui exists in the PlayerGui, with the Instance:FindFirstChild() method. If the ScreenGui was found, we will not do anything. If not, we will clone it so they have it.

01script.Parent.Touched:Connect(function(part)
02    local player = game.Players:GetPlayerFromCharacter(part.Parent)
03 
04    if player then -- we should make sure it's player first
05 
06        if player.PlayerGui:FindFirstChild("ScreenGui") then return end
07        -- if a ScreenGui was found, do not do anything, just return out the function
08 
09            local shop = game.ServerStorage.ScreenGui:Clone()
10            shop.Parent = player.PlayerGui
11    end
12end)
Ad
Log in to vote
0
Answered by 6 years ago

Make it so when you touch a part all the rest of the gui's transparency will be 1 except the one you want to show and use the "OnTouchEnded" function to make the guis reappear after the part is not being touched

Answer this question