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)
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?
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.
--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.
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.
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)
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)
[Put the Mission UI under the script that will do that code, it should work]