Hello. I have two pieces of code down below. What they do together is open and close a shop when the respective one is clicked on.
The first one below is a Script (not local) which is attached to a part. When that part is clicked the GUI moves onto the screen.
--Activates when player clicks weapon shop button
script.Parent.ClickDetector.MouseClick:Connect(function(Player)
local Debounce = Player.PlayerGui.ShopsGui.Debounce
print(1)
if game.ReplicatedStorage:WaitForChild("Stats"..Player.Name):WaitForChild("PlayerGame"):WaitForChild("ValueInLobby").Value == true and game.ReplicatedStorage:WaitForChild("Stats"..Player.Name):WaitForChild("PlayerGame"):WaitForChild("ValueInGame").Value == false then
print(2)
game.ReplicatedStorage:WaitForChild("Stats"..Player.Name):WaitForChild("PlayerGame"):WaitForChild("ValueInWeaponShop").Value = true
local ShopGui = Player.PlayerGui.ShopsGui.WeaponShop.ScreenGui
ShopGui.Enabled = true
ShopGui.HolderFrame.Page1.ZIndex = 3
ShopGui.HolderFrame.Page2.ZIndex = 2
ShopGui.HolderFrame.PageShop.ZIndex = 1
ShopGui.HolderFrame:TweenPosition(UDim2.new(0,0,0,0),"Out","Quad",0.5)
print(3)
end
end)
The second one below is a Local Script attached to an ImageButton. When clicked the shop moves off-screen.
--Activates when clicked. Closes shop
local Debounce = game.Players.LocalPlayer.PlayerGui.ShopsGui.Debounce
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage:WaitForChild("Stats"..(game.Players.LocalPlayer.Name)):WaitForChild("PlayerGame"):WaitForChild("ValueInWeaponShop").Value = false
script.Parent.Parent:TweenPosition(UDim2.new(0,0,1,0), "Out", "Quad", 0.5)
end)
Problem: This code works perfectly fine the first time I click on the part to open the shop and click on the ImageButton to close the shop. However the second time I click on the part, the shop does not open (I tested clicking the ImageButton in this stage and it works fine). The print(1), print(2), and print(3) you see in the first script also print the second time I use it too, so the console is getting through the whole script.
Any Ideas?
PS: The if statements are really long which is why they look like that, but the point is that the program reads them and gets into them.
Thanks in advance.
- Zipps
