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

How can I make ScreenGui visible for 3s only?

Asked by
amalion -3
3 years ago

I'm trying to make a frame turn visible for 3 seconds every time proximity prompt is triggered, the script I have turns it visible but to reverse it I must pres E again. Also I'm curious if frame.visible can be changed when the players gets out of X max distance and how.

local prompt = script.Parent
local open = false
prompt.Triggered:Connect(function(player)
    local PlayerGui = player:WaitForChild("PlayerGui")
    local ScreenGui = PlayerGui.ScreenGui
    local Frame = ScreenGui.Frame
    if open == false then
        open = true
        Frame.Visible = true
    else
        open = false
        Frame.Visible = false
    end
end)
0
You have to use a remote event I believe, because you can't and (shouldn't change) guis on the server AnasBahauddin1978 715 — 3y

1 answer

Log in to vote
0
Answered by
NGC4637 602 Moderation Voter
3 years ago
Edited 3 years ago

Here's what you can do:

local prompt = script.Parent
open = false

prompt.Triggered:Connect(function(player)
    local plrGui = player:FindFirstChild("PlayerGui")
    local scrGui = plrGui.ScreenGui
    local Frame = scrGui.Frame
    if open = false then
        open = true
        Frame.Visible = true
        delay(3, function() -- delays the following function by 3 seconds
            Frame.Visible = false -- puts the frame back to being invisible
            open = false
        end)
    else -- if open = true then
        return -- the function does nothing
    end
end)

However, changing client-sided things on a server script can cause errors. Instead, place a local script in StarterGui, or StarterPlayerScripts.

afterwards, add a RemoteEvent. You should place in ReplicatedStorage.

then change the server script (normal script) to be this:

local prompt = script.Parent
open = false

prompt.Triggered:Connect(function(player)
    if open = false then
        local waittime = 3
        open = true
        game.ReplicatedStorage.RemoteEvent:FireClient(player,waittime)
        wait(waittime)
        open = false
    else
        return
    end
end)

Finally in the local script, put this:

local Event = game.ReplicatedStorage.RemoteEvent
local player = game.Players.LocalPlayer

Event.OnClientEvent:Connect(function(waittime)
    local plrGui = player.PlayerGui
    local scrGui = plrGui.ScreenGui
    local frame = scrGui.Frame
    frame.Visible = true
    wait(waittime)
    frame.Visible = false
end)
Ad

Answer this question