What is wrong with my proximityprompt script?

I’ve been confused on why this isn’t working. I am making a showcase, and I put a ProximityPrompt onto an object. The prompt is supposed to open a GUI in StarterGui, but it WON’T WORK!!! HELP

script.Parent.Triggered:Connect(function()

game.StarterGui.Credits.Frame.Visible = true

end)

Ah, the common StarterGui issue

This happens because you’re changing the Gui from the server’s side, not your client’s side (Or what you currently see on your screen)

In ROBLOX, there are 2 sides that each share their own different perspectives: The Client and the Server

The Client side is mainly used for UI Interaction, detecting Input from a Player, and such

The Server side however is used to handle the main game, such as being changing a Player’s Stats, resetting a Player’s Health to 0, and etc

Depending on what script this is, you can reference the Player parameter provided by the Triggered Event as that’ll give you the Player Instance:

script.Parent.Triggered:Connect(function(Player)
    Player.PlayerGui.Credits.Frame.Visible = true
end)
3 Likes

I’ll try that out once I can, I have to go somewhere. I’ll inform you once I try it. It’s a LocalScript, by the way.

If this is a LocalScript, change it to a Regular Script & reference it the way I showed you

LocalScripts will not work if they’re a descendant of the workspace (There are some exceptions with the Player’s Character however)

LocalScripts are Local/Client-Sided, that means only you as an individual can see it

1 Like

I’m back, and I tested it out. THANK YOU SO MUCH! It worked! This was a really valuable learning experience for me. I’m so grateful for people like you!!!

Ah, one problem though. The prompt only works once. I open the credits GUI, close it, then try to open it with the ProximityPrompt again, and nothing happens. Do you know any way to fix this?

You will need to use something called a debounce. A debounce can be a variable that stores a true and false value which we can change once the UI opens and closes. Also I recommend moving everything to client instead of the server for easier use. Here is an example:

local Debounce = false --Our debounce value

Prompt.Triggered:Connect(function(Player) --Prompt triggered
	if Debounce then --Check if debounce is true
		--Close UI
	else
		--Open UI
	end
	Debounce = not Debounce --Flip the value (If true goes false, if false goes true)
end)
1 Like

So how would I be able to move everything to the client? Also, where would I put the script you gave me? I’m sure you can tell I’m a beginner scripter lol, I’m not great at this.

You can put the code I provided within a local script. You can put the local script in any client sided service or instance such as StarterGui or StarterPack like shown in this photo.
image
Running this code on client will mean that any code that is ran (opening our UI) is only shown for the one person behind the device. For example if we create a part within a server script everyone in the game will see the part, if we create a part within a local script only that one person can see the part.

1 Like

Only problem: I see you have that “Prompt:Triggered” etc. Is that to detect if the prompt is triggered? If so, wouldn’t I want to have that under the Part that I have the ProximityPrompt on? Sorry if it’s obvious, I’m just a little confused.

Yeah I was just using that as my example.
In your case it will be:
game.Workspace.YourPart.ProximityPrompt.Triggered:Connect(function()
Alternatively you can define it as a variable
local Prompt = game.Workspace.YourPart.ProximityPrompt

1 Like

Ohhh, okay, so rather than detecting that the Prox. Prompt has been detected from within the part, I put the script in my credits GUI, or places like that. I’ll try that out!

Yes as a developer it’s good to organize code and your instances in places where it would make sense so it’s easier for yourself and others to navigate your workspace. Also local scripts generally do not run within a part.

1 Like

Wouldn’t that be Prompt.Triggered? I’m getting an error when I have a colon, but when I use a period there isn’t an error. Should I keep it as a colon or change it to a period?

Change it to a period, sorry that was a mistake on my side because I wasn’t in studio.

1 Like

Alright its working BUT ughhhhh one more problem. It takes 2 activations to show the UI again.

One second, I wrote the code without being in studio so let me fix it and I’ll edit this post with the answer.

1 Like

The code that I provided earlier works perfectly fine in my case.

local Prompt = game.Workspace:WaitForChild("Part").ProximityPrompt
local UI = script.Parent

local Debounce = false

Prompt.Triggered:Connect(function()
	if Debounce then
		UI.Frame.Visible = false
	else
		UI.Frame.Visible = true
	end
	Debounce = not Debounce
end)

image

Weird, I have it set up in the same way, but it’s still taking 2 activations to work.

Can you provide your code so I can help?
Is your debounce value set to false?
Is your frame by default have visible set to false?

Your debounce value should be true or false depending if the frame is already visible. If the frame is already visible by default then change the debounce value to true so it starts open and closes.

1 Like