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

How do I make script that opens up a gui I touch a brick and once I off the part the gui goes away?

Asked by 5 years ago
Edited 5 years ago
-- I made this script, it is a server script
-- It does NOT work, I did many attempts
-- I want the gui only to appear for the player that touched the part
-- I do not know if this should be a localscript or serverscript
-- Please help

if script.Parent.Touched == true then
    script.Parent.keyGui:DuplicateIntoPlayerGui()
end
if script.Parent.Touched == false then
    while true do(nothing)
        game.Nothing = true
    end
0
keep the gui disabled until you touch it and when you leave the part it disables? sean_thecoolman 189 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

You can use touched and touch ended events to trigger GUIs Example:

-- LocalScript
local part = script.Parent
local gui = game:GetStorage("ReplicatedStorage"):WaitForChild("TouchGui")
local last = nil

local function Touch(tpart)
    if tpart then
        local character = part:FindFirstAncestorWhichIsA("Model")
        if character then
            local player = game:GetService("Players"):GetPlayerFromCharacter(character)
            if player and gui then
                local exists = player:WaitForChild("PlayerGui"):FindFirstChild(gui.Name)
                if notexists then
                    local clone = gui:Clone()
                    clone.Parent = player:WaitForChild("PlayerGui")
                end
                last = tpart
            end
        end
    end
end

local function UnTouch(tpart)
    if tpart then
        if tpart == last then
            local character = part:FindFirstAncestorWhichIsA("Model")
            if character then
                local player = game:GetService("Players"):GetPlayerFromCharacter(character)
                if player and gui then
                    local exists = player:WaitForChild("PlayerGui"):FindFirstChild(gui.Name)
                    if exists then
                        exists:Destroy()
                    end
                    last = nil
                end
            end
        end
    end
end

part.Touched:Connect(Touched)
part.TouchEnded:Connect(UnTouched)
0
Thanks. GamingWithFlight 80 — 5y
0
You're very welcome. LucarioZombie 291 — 5y
Ad

Answer this question