Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make ScreenGui visible for 3s only?

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)

1 comment

0

You have to use a remote event I believe, because you can't and (shouldn't change) guis on the server

1 answer

✓ Accepted answer

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)

1 comment

This discussion is preserved as it was. New answers, comments, and votes are closed.