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

My Client Side GUI will only show up one time from a remote event?

Asked by 5 years ago
Edited by Azarth 5 years ago

Hi I am working on a tycoon and am trying to create a GUI that pops up for the user when they try to buy something with insufficient funds. The GUI will pop up the first time someone tries to buy something without enough money, but it does not pop up again. Could anyone help me troubleshoot this?

Here is my server side script:

function InsufficientFunds()
        local Insuff = Instance.new("RemoteEvent")
        Insuff.Parent = game.ReplicatedStorage
        Insuff.Name = "Insuff"
        Insuff:FireClient()
end

---- Some stuff here if he has enough money---- This part works
else
    Sound(v, Settings.Sounds.ErrorBuy)
    InsufficientFunds() --Calls my insufficientFunds function

client side:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local player = Players.LocalPlayer
local Insuff = ReplicatedStorage:WaitForChild("Insuff")
local playerGui = player:WaitForChild("PlayerGui")
local shop = player.PlayerGui.Nope.Shop
local function InsufficientFunds()
    shop.Visible = true
    wait(5)
    shop.Visible = false
end

Insuff.OnClientEvent:Connect(InsufficientFunds())

0
My GUI is also popping up for everyone in the game. What could be going on here? Channy97 10 — 5y

1 answer

Log in to vote
0
Answered by
JakyeRU 637 Moderation Voter
5 years ago

Greetings. The reason why it appears only one time, is that you are creating multiple remote events with the same time, each time the function InsufficientFunds is ran. Please avoid doing that. Creating manually an remote event called InsufficientFunds is enough.

The reason why it appears for everyone is that FireClient() requires at least one argument. First argument has to be the player. For example:

RemoteEvent:FireClient(game.Players.JakyeRU)

Here's your fixed script:

Server Script:

local RemoteEvent = Instance.new("RemoteEvent", game.ReplicatedStorage)

-- Your Buy Function Here

wait(5)
RemoteEvent:FireClient(game.Players.JakyeRU)

Local Script:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Player = Players.LocalPlayer
local RemoteEvent = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local PlayerGui = Player:WaitForChild("PlayerGui")
local Shop = PlayerGui.Nope.Shop

function InsufficientFunds()
    Shop.Visible = true
    wait(5)
    Shop.Visible = false
end

RemoteEvent.OnClientEvent:Connect(InsufficientFunds())
Ad

Answer this question