Screengui won't appear on screen after second trigger

I’m having issues putting a canvasgroup (frame) onto the screen when the player activates a proximityprompt.

The first time it works all fine, but when the player activates the button in the localscript, it just wont re-appear when I activate the proximityprompt again.

Server script: (proximity prompt handler)

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local proximityPrompt = script.Parent

local function onProximityPromptTriggered(player)
	local playerGui = player:WaitForChild("PlayerGui")
	local frame = playerGui:FindFirstChild("RelicsTeleport"):WaitForChild("Wrapper")

	if frame then
		local on = TweenService:Create(frame, TweenInfo.new(0.5, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), { GroupTransparency = 0, Position = UDim2.fromScale(0.387, 0.171) })

		frame.Visible = true
		on:Play()
	end
end

proximityPrompt.Triggered:Connect(onProximityPromptTriggered)

Local Script: (in a screengui, under a textbutton)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")

local proximityPrompt = game.Workspace.Map.Relics["Relic 1"]:WaitForChild("Prox"):WaitForChild("ProximityPrompt")
local proximityPrompt2 = game.Workspace.Map.Relics["Relic 1"]:WaitForChild("CamProx"):WaitForChild("ProximityPrompt")
local union = proximityPrompt.Parent.Parent:WaitForChild("Symbol")

local button = script.Parent.Parent
local imageLabel = script.Parent

local player = game.Players.LocalPlayer
local productId = 2837973045

local normalColor = button.BackgroundColor3
local hoverColor = normalColor:lerp(Color3.new(1, 1, 1), 0.2)

local screenGui = Instance.new("ScreenGui", player.PlayerGui)
screenGui.IgnoreGuiInset = true
local fadeFrame = Instance.new("Frame", screenGui)
fadeFrame.Size = UDim2.new(1, 0, 1, 0)
fadeFrame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
fadeFrame.BackgroundTransparency = 1

local frame = script.Parent.Parent.Parent.Parent.Parent.Parent
local sound = frame.Click

local off = game:GetService("TweenService"):Create(frame, TweenInfo.new(0.5, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), { GroupTransparency = 1, Position = UDim2.fromScale(0.387, 0.271) } )

button.MouseEnter:Connect(function()
	local dataFolder = player:FindFirstChild("Data")
	if dataFolder then
		local relicsDataFolder = dataFolder:FindFirstChild("RelicsData")
		if relicsDataFolder then
			local relic1Value = relicsDataFolder:FindFirstChild("Relic1")
			if relic1Value and relic1Value.Value == true then
				button.BackgroundColor3 = hoverColor
			end
		end
	end
end)

button.MouseLeave:Connect(function()
	local dataFolder = player:FindFirstChild("Data")
	if dataFolder then
		local relicsDataFolder = dataFolder:FindFirstChild("RelicsData")
		if relicsDataFolder then
			local relic1Value = relicsDataFolder:FindFirstChild("Relic1")
			if relic1Value and relic1Value.Value == true then
				button.BackgroundColor3 = normalColor
			end
		end
	end
end)

button.MouseButton1Click:Connect(function()
	sound:Play()
	
	local dataFolder = player:FindFirstChild("Data")
	if dataFolder then
		local relicsDataFolder = dataFolder:FindFirstChild("RelicsData")
		if relicsDataFolder then
			local relic1Value = relicsDataFolder:FindFirstChild("Relic1")
			if relic1Value and relic1Value.Value == true then
				local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
				local fadeInTween = TweenService:Create(fadeFrame, tweenInfo, {BackgroundTransparency = 0})
				local fadeOutTween = TweenService:Create(fadeFrame, tweenInfo, {BackgroundTransparency = 1})

				fadeInTween.Completed:Connect(function()
					player.Character:SetPrimaryPartCFrame(game.Workspace.Map.Relics["Relic 1"]:WaitForChild("Pos").CFrame)
					off:Play()
					task.wait(0.5)
					frame.Visible = false
					fadeOutTween:Play()
				end)

				fadeInTween:Play()
			else
				local success, result = pcall(function()
					game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
				end)

				if success and result then
					local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
					local tween = TweenService:Create(union, tweenInfo, {Color = Color3.fromRGB(143, 143, 143)})
					tween:Play()

					union.PointLight.Enabled = true

					local sound = union:FindFirstChild("Sound")
					if sound then
						sound:Play()
					end

					proximityPrompt.Enabled = false
					proximityPrompt2.Enabled = true
				end
			end
		end
	end
end)

local function updateIconBasedOnRelic1()
	while true do
		local dataFolder = player:FindFirstChild("Data")
		if dataFolder then
			local relicsDataFolder = dataFolder:FindFirstChild("RelicsData")
			if relicsDataFolder then
				local relic1Value = relicsDataFolder:FindFirstChild("Relic1")
				if relic1Value then
					if relic1Value.Value == true then
						imageLabel.Image = "rbxassetid://118448551311907"
					else
						imageLabel.Image = "rbxassetid://75694552427029"
					end
				end
			end
		end

		task.wait(0.1)
	end
end

task.spawn(updateIconBasedOnRelic1)

ScreenGui Directory:

image

Workspace Directory:

image

Thanks for your help! :heart:

Still needing assistance on this.

I have tried debugging the code, here is the output and code below:

image The red is the first proximity trigger, blue is second

Code:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")

local proximityPrompt = script.Parent

local function onProximityPromptTriggered(player)
	local playerGui = player:WaitForChild("PlayerGui")
	if playerGui then
		print("PlayerGui found")
		local frame = playerGui:FindFirstChild("RelicsTeleport"):WaitForChild("Wrapper")
		if frame then
			print("Frame found")
			local on = TweenService:Create(frame, TweenInfo.new(0.5, Enum.EasingStyle.Quint, Enum.EasingDirection.InOut), { GroupTransparency = 0, Position = UDim2.fromScale(0.387, 0.171) })

			frame.Visible = true
			print("Frame set to visible")
			on:Play()
			print("Tween started")
		else
			print("Frame not found")
		end
	else
		print("PlayerGui not found")
	end
end

proximityPrompt.Triggered:Connect(onProximityPromptTriggered)

I am still requesting help on this. This is majorly affecting my game and I need a solution soon.

In short, the server goes to set the frame to visible, but still sees it as already being visible, so nothing happens. (This is one of the reasons why it isn’t advised that you change UI on the server.

A simple workaround is just to replace

frame.Visible = true

with

frame.Visible = false
frame.Visible = true

(you may need to add a tiny delay between the 2)

I did that and the thing you suggested seems to be working, but there is another issue

The GroupTransparency stays to 1 even though the screengui becomes transparency 0

It’s an issue with tweening, any reason why?

I decided to just fire a remote event in the end after all the struggling.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.