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 5 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.

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

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 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.

script.Parent.Touched:Connect(function(part)
    local player = game.Players:GetPlayerFromCharacter(part.Parent)

    if player then -- we should make sure it's player first

        if player.PlayerGui:FindFirstChild("ScreenGui") then return end
        -- if a ScreenGui was found, do not do anything, just return out the function

            local shop = game.ServerStorage.ScreenGui:Clone()
            shop.Parent = player.PlayerGui 
    end
end)

Ad
Log in to vote
0
Answered by 5 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