Script
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local clickDetector = script.Parent.ClickDetector local shopOpenRequest = Instance.new("RemoteFunction") shopOpenRequest.Name = "ShopOpenRequest" shopOpenRequest.Parent = ReplicatedStorage local function clicked(player) shopOpenRequest:InvokeClient(player) end clickDetector.MouseClick:Connect(clicked)
Local Script
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local player = Players.LocalPlayer local playerGui = player:WaitForChild("PlayerGui") local shopOpenRequest = ReplicatedStorage:WaitForChild("ShopOpenRequest") local shop = script.Parent.Parent shop.Enabled = false local function onShopOpenRequested() shop.Enabled = true end shopOpenRequest.OnClientInvoke = onShopOpenRequested()
This script would run immediately after you join server and never work again. I need solution on how to make this script run only when the clickDetector is activated and run more than once.
This happens because of shop.Enabled = true
. Basically, whenever the player clicks on the button, shop.Enabled will be set to true, and not get back to false.
Here's a better version of the OnShopOpenRequested()
:
local function onShopOpenRequested() shop.Enabled = not shop.Enabled -- This is a toggle basically end shopOpenRequest.OnClientInvoke = onShopOpenRequested()