Two Identical GUI-modifying Scripts Conflicting with Each Other

In my experience, I have made a placard system where a user can hold a ProximityPrompt on multiple placards to open a GUI with different text:

local Prompt = script.Parent

Prompt.Triggered:Connect(function(player)
	player.PlayerGui.ArtInfo.Frame.title.Text = "Title"
	player.PlayerGui.ArtInfo.Frame.description.Text = "Description"
	player.PlayerGui.ArtInfo.Frame.dateOfCreation.Text = "XXXX-XXXX"
	if player.PlayerGui.ArtInfo.Enabled == true then
		player.PlayerGui.ArtInfo.Enabled = false
	else 
		player.PlayerGui.ArtInfo.Enabled = true
	end
end)

The ArtInfo (Placard) GUI has an almost identical script, for closing the GUI via a MouseButton1Click event, where the instance player is replaced with LocalPlayer:

script.Parent.MouseButton1Click:Connect(function()
	if game.Players.LocalPlayer.PlayerGui.ArtInfo.Enabled == true then
		game.Players.LocalPlayer.PlayerGui.ArtInfo.Enabled = false
	else 
		game.Players.LocalPlayer.PlayerGui.ArtInfo.Enabled = true
	end
end)

For some reason, both of these scripts seem to conflict with each other. If the player opens the ArtInfo via a ProximityPrompt and closes the ArtInfo through the GUI (instead of through the ProximityPrompt), the player has to click the ProximityPrompt two times to open it. However, if the player only uses the ProximityPrompt to open and close the ArtInfo GUI, the player only has to use the ProximityPrompt once.

To see this in action, visit this experience and open any placard in any gallery, close it through the button in the GUI, and try opening the ArtInfo GUI again

This makes some players think that the Placards do not work, and I need to fix this issue as soon as possible.

Is this a bug with Roblox that I should report, or is there something I should change in my scripts?

Wouldn’t it be easier to have the logic for the ProximityPrompt in the same script as the MouseButton1Down connection? Also instead of doing:

I would personally do:

player.PlayerGui.ArtInfo.Enabled = not player.PlayerGui.ArtInfo.Enabled

(Same for the code inside the MouseButton1Down function)

Logic operators are pretty powerful once you get used to them :wink:

That’s cool! I should try using Logic Operators more.
So I should recenter the whole system on Remote Events?

I don’t think you necessarily need RemoteEvents to achieve what you’re trying to do since ProximityPrompts work locally as well, but if you do need them I would consider using Attributes instead as I think they’re most likely better suited for what I think you’re trying to do (Remember though that if you change the value of the attribute on the client, it won’t be replicated to the server!)

I was planning on using RemoteEvents as both scripts seem to conflict with each other no matter what changes I make.
Are you saying this is an issue with the set attributes of the ProximityPrompt itself?

I re-read the main post carefully and I think I figured out what’s happening. The issue you’re experiencing is most likely caused by replication. When you set the ScreenGui.Enabled property in the LocalScript, the server script that contains the ProximityPrompt.Triggered connection does not receive the new value due to the way replication works for sercurity. The best way to solve this problem is to have the ProximityPrompt.Triggered connection in the same LocalScript as the MouseButton1Down connection

That makes much more sense now. Since I have multiple ProximityPrompt scripts on different instances, I will have to use RemoteEvents. Thank you so much for your help!

1 Like

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