I’m currently trying to create a UI toggle which works when you open it the first time, but when the UI is closed again it isn’t allowed to reopen for some reason.
I have debugged my code sufficiently to work out where the problem lies; the code is below:
ShopTouch.Touched:Connect(function(Hit)
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Player ~= nil then
local PlayerGui = Player.PlayerGui
PlayerGui.Services.GUINavigationClient.UIOpen.Value = PlayerGui.Middle.Holder.Cosmetics
print("Set")
end
end)
Each time I want to reopen the menu, the “Set” line is printed however the value itself isn’t changed. I know this because I’ve hooked up a “Changed” listener elsewhere in the code which isn’t being fired.
First thing, you should check for a humanoid when your part is touched so it doesn’t error.
Second, you are only assigning something to the ObjectValue once, so you’d have to make its value nil when you are closing the shop. This should trigger the .Changed event.
I am setting the value to nil elsewhere in the code and when I run this part of the code, the value is set to nil. However when this code is run (and it is being run, we know through the print) it isn’t setting the value for some reason.
In regards to the Humanoid detection, I have a couple more sanity checks that I didn’t include in this post because I wanted to focus on the problem. I have implemented a humanoid check as well as a health check to see whether the player is alive or not.
Hmm, that’s weird. When you say elsewhere in the code, do you mean in a different script? This shouldn’t be an issue if both scripts are either local or server scripts, but if one’s local and one’s server sided, that could cause issues with the .Changed event as server scripts won’t detect any client changes. You could also try to switch to remote events if that interests you, in case your UIs aren’t synchronizing or something.