Proximity Promt Problem!

For some reason this prximity promt wont work the second time this is normal script.

script.Parent.Triggered:Connect(function(player)
	local npcDialogueFrame = player.PlayerGui.MainGui.NpcDialogueFrame -- this is where it stops the second time
	
	npcDialogueFrame.Visible = true
	
end)

And this is a local script wich closes teh gui I opend in script 1.

script.Parent.MouseButton1Up:Connect(function()

script.Parent.Parent.Visible = false

end)

When the server shows the frame to a player, both will see that the frame is Visible. However, if you decide to close it on the client, the server will still see that the frame is Visible, because client actions won’t be replicated to the server.

You may want to use a RemoteEvent instead, and tell the server to close the dialogue there as well.

no it arleady opens the clients gui and closes it.

local npcDialogueFrame = player.PlayerGui.MainGui.NpcDialogueFrame

if you are always referring to the same dialogue. take this out of the trigger

are there any warnings??

2 Likes

no theres no warnings so i have no idea what the problem is

2 Likes

Either do both of them locally, or both of them on the server.
Doing both of them locally seems like the better thing to do since the first script will already work on a local script and there’s no need to tweak it. Also, its GUI.

1 Like

You don’t get how server-client works, do you?

1 Like

idk if it will work but try it

script.Parent.Triggered:Connect(function(player)
	local npcDialogueFrame = player.PlayerGui.MainGui.NpcDialogueFrame

	npcDialogueFrame.Visible = false
	npcDialogueFrame.Visible = true
end)
2 Likes

Let’s go over this again. Your issue here is that:

  • From the server, you show a player’s GUI by setting Visible to true.
  • From the client, you hide it by setting it to false.

If you think that’s how it works, have fun figuring out the issue.
Because what you’re doing is exactly the issue.

Remember how server and client works?

  • Server changes are visible to the server and ALL the clients.
  • Except animations, client changes are ONLY visible to the own client.

Say with an example:

  • If you create a part using a Server script, everyone can see it.
  • If you create a part using a LocalScript, only the client can see it, but still be able to use it. With this example in place, everyone else will see you flying because they don’t see a part, since only you have it.

Get it now? What do you think your issue is?

When you set the Frame to Visible from a Server script, changes are visible to both the server and that client.
Now I want you to listen to this very carefully:
If you close the frame on the client, only the client will see that it’s closed. This means that the server still thinks that Frame.Visible = true, so

script.Parent.Triggered:Connect(function(player)
	local npcDialogueFrame = player.PlayerGui.MainGui.NpcDialogueFrame
	
	npcDialogueFrame.Visible = true
	-- it's already true so it does nothing.
end)

no longer works because it’s already true.

Your issue has two fixes: Either place the Prompt script in a LocalScript, or use a RemoteEvent. It’s as simple as this.

1 Like

No I only make it visible for the client and inviseble for the client to thats why its

player.PLayerGui

And the player = the player who triggerd the proximity promt and in the other script it just closes the gui also for that player because theres a buttin that frame that closes what ever frame the button was inside of so it does the client both true and false, I fixed it btw by making them both in starterGui and local scripts.

1 Like

But you are accessing it from the server, and the server doesn’t know that the client has it open or closed.

but how can i know if it is then?

1 Like

Using Remote Events. The client can directly tell the server if they have it open or not.

1 Like

How do i do that, I have no idea.

OK, let’s use the commander analogy.
Pretend you are the commander (the server) of a giant army. The army is split into divisions (clients). The divisions know what the instructions from the commander are, but, the problem is, the commander doesn’t know what is going on at the battlefield with the divisions. The commander needs messengers (remote events).
These messengers will tell the commander what is going on, and the commander can send a reply to singular divisions with instructions.

Remote events work the same way - the server wants to know what’s going on, so a client can send that info.
Create a remote event in ReplicatedStorage. Let’s call it VisibleRemote.
To let the server know if it’s visible, we can use :FireServer on a local script

VisibleRemote:FireServer(npcDialogueFrame.Visible)

This will tell the server whether or not npcDialogueFrame is visible or not.

Now, on the server side. To check if the server has recieved a message, we can use OnServerEvent

VisibleRemote.OnServerEvent:Connect(function()
    -- bla bla bla, do stuff here
end)

I hope this helps you understand remote events a bit more

1 Like

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