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)
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)