What is wrong with my script?

This only works once, no errors. It will put my GUI inside the player. And after that it seems to stop running. Even though when the GUI is removed via :Remove() function.

[Edit: The remove of the GUI is inside a Local script btw, would that matter?
It seems like the player argument in this proximity trigger isn’t updating each time it’s prompted? So even though the GUI is removed, it’s still using the old player argument that had the GUI? Anyone have any ideas?

local ProximityPrompt = script.Parent
ProximityPrompt.Triggered:Connect(function(player)
	if player.PlayerGui:FindFirstChild("Mission1GUI") == nil then
		local missionGiver = game.ReplicatedStorage.GUIFolder.Mission1GUI:Clone()
		missionGiver.Parent = player.PlayerGui
	end
end)
3 Likes

Maybe try to change your condition from :
player.PlayerGui:FindFirstChild("Mission1GUI")
To:
player.PlayerGui:WaitForChild("Mission1GUI")

The problem may be that the PlayerGui is not created yet / not a child of the player yet. Then it would create one (as you want it to work). But if the proximity prompt is triggered again, but faster than the creation (cloning) of the Gui, it will clone another one.
Then you end up with more than one child of player with the same name, which causes it not to work.

This might not be the problem, but it could be.
Hope this helps though !

If the GUI doesn’t exist in the player, then wouldn’t ‘WaitForChild’ result in an infinite yield?

Even if for some reason the player gui hadn’t loaded. I’ve tried this prompt many times over, it should redefine the player argument each time you prompt it right?

1 Like

Oh, you’re right, I thought there was already a Gui inside your player.

The problem can also be that the prompt is triggered too fast : fast enough to be called again before the first execution has even ended.
I think there is a function that allows you to wait for an action to end before continuing the script, not sure how it works though.

Yes, because you’re removing the Gui on the Client. So the Server still thinks you got the UI (bc you gave the player the ui on the server).

2 Likes

So I need a client- server event to remove it then I guess?

Yes, you do. ​​​​​​​​​​​​​​​​​​​​​​

--Main
local ProximityPrompt = script.Parent
ProximityPrompt.Triggered:Connect(function(player)
	if player.PlayerGui:FindFirstChild("Mission1GUI") == nil then
		local missionGiver = game.ReplicatedStorage.GUIFolder.Mission1GUI:Clone()
		missionGiver.Parent = player.PlayerGui
	end
end)

--Closing UI [2 ways]
--1: close it from the script above

--2: use a remote event 
local RS = game:GetService("ReplicatedStorage")

script.Parent.MouseButton1Click:Connect(function()
	RS:WaitForChild("MyRemote"):FireServer(script.Parent.Parent)-- the UI
end)
game.ReplicatedStorage.MyRemote.OnServerEvent:Connect(function(Player,UI)
	Player.PlayerGui:FindFirstChild(UI.Name):Destroy()
	--or you can just invisible it
end)

So new problem, so now I delete the GUI via client - server event and that works.

But my quest accept button below, even though the GUI is created and exists it’s not recognizing it’s there. Is that because this is a server script, do I need a server to client event to create the GUI in the players PlyrGui?

local ProximityPrompt = script.Parent
ProximityPrompt.Triggered:Connect(function(player)
	if player.PlayerGui:FindFirstChild("MissionGUI1") ~= nil then return end
	print("running")
		local missionGiver = game.ReplicatedStorage.GUIFolder.Mission1GUI:Clone()
		missionGiver.Parent = player.PlayerGui
end)

If you created the UI in other script[ as long as the server knows it] or the ui is automatically there, the server should be able to recognize it.

But - if you created the UI in a different way, make sure the server knows it.
Since you’re using a Server script, there is no need to actually create the UI with a remote.
You can simply clone the UI from the server to the player[you can put the UI inside the script if you want] And just clone it to PlayerGui

That’s the thing this prompt is a server script. And it’s checking if a GUI by that name exists. And it’s not recognizing it. I even did a check and printed out the contents of the player gui in the same script and its forsure there on the server.

Are you using a remote or straight doing it on the server script?

The script I posted above is a server script and that’s the only script that deals with replicating the GUI to the player (in this case part of a proximity prompt)

if player.PlayerGui:FindFirstChild("MissionGUI1") ~= nil then return end

basically this line isn’t working even though the GUI is present.

Well, the original script looks totally fine

local ProximityPrompt = script.Parent
ProximityPrompt.Triggered:Connect(function(player)
	if not player.PlayerGui:FindFirstChild("Mission1GUI")  then
		local missionGiver = game.ReplicatedStorage.GUIFolder.Mission1GUI:Clone()
		missionGiver.Parent = player.PlayerGui
	end
end)
local ProximityPrompt = script.Parent
ProximityPrompt.Triggered:Connect(function(player)
    print("running")
	if player.PlayerGui:FindFirstChild("MissionGUI1") then 
       print("Player already has the mission in his UI!")
    else
       local missionGiver = game.ReplicatedStorage.GUIFolder.Mission1GUI:Clone()
	   missionGiver.Parent = player.PlayerGui
    end
end)

Same thing: https://gyazo.com/8efd929cef464fab31921f3b27a50d95

Weird. Alright, I’ll now take a look into it and come back asap.

1 Like

Try this :

local ProximityPrompt = script.Parent
ProximityPrompt.Triggered:Connect(function(player)
	if not player.PlayerGui:FindFirstChild("Mission1GUI") then
		local missionGiver = script.Mission1GUI:Clone()
		missionGiver.Parent = player.PlayerGui
	end
end)

image

[Put the Mission UI under the script that will do that code, it should work]

Although, even if I put that inside ReplicatedStorage, it’d work. That’s weird that it doesnt work to you.