Hello, I am having trouble with opening a shop gui. But the problem is that it only opens once, here are the scripts:
This script puts the gui inside of the player gui
local clonedGui = script.Parent:Clone()
local gui = script.Parent
if gui.Parent == game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui") then
print("Gui already in playergui")
else
clonedGui.Parent = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
print("Gui put in playergui")
end
And this script opens it
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
game:GetService("Players"):FindFirstChild(hit.Parent.Name).PlayerGui.ItemAndRebirthShop.Frame.Visible = true
end
end)
The code is not efficient and you are handling GUI on server (laggy) . The reason for not working is you are changing its Visibility to true then never to False. Now , put the second script in a local Script inside StarterPlayer or somewhere and add a Touched and TouchEnd Event , once touched check if the Touched Character is the Local Player’s Character and then change the Visibility of the GUI to true. Once TouchEnded check if the Touched Character is the Local Player’s Character and then change the Visibility of the GUI to false or you can make it based on toggle.
Here a small script serverside.
Need to be a Localscript and under the ShopGUI.
ShopGUI should be in StarterPlayerGui (Or at least in the player UI by default)
local Shop = --// PUT THE PART THAT PLAYER NEED TO TOUCH TO OPEN THE SHOP
local Bool = false
Shop.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent:FindFirstChildWhichIsA("Humanoid"))
if Player and Player == game.Players.LocalPlayer then
if not Bool then
Bool = true
Script.Frame.Visible = true
end
end
end)
script.Parent.Frame.ExitButton.MouseButton1Click:Connect(function() --// PUT EXIT BUTTON
Bool = false
Script.Frame.Visible = false
end)