Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I need help on server - client communication using remotefunction?

Asked by
Neon_N 104
4 years ago

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.

1 answer

Log in to vote
0
Answered by
bluzorro 417 Moderation Voter
4 years ago

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()
0
Thanks but It doesn't work Neon_N 104 — 4y
Ad

Answer this question