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

Why does the button make several gui instead of one?

Asked by
Viking359 161
6 years ago

I'm converting my game to FE and I redid my gui opener. Now, it opens a bunch of random gui instead of just one when I click the button. Server-side

local ShowGui = game:GetService("ReplicatedStorage").Menu

ShowGui.OnServerEvent:Connect(function(player)
game.ServerStorage.GUI.TheMenu:Clone().Parent = player:WaitForChild("PlayerGui")
or game.ServerStorage.GUI.TheMenu:Clone().Parent == player:FindFirstChild("PlayerGui")
end)

(There is a remote event 'Menu') Client-side

local ShowGui = game.ReplicatedStorage.Menu

script.Parent.MouseButton1Click:Connect(function()
ShowGui:FireServer()
end)

It opens the menu, but also some other gui like 'Help' 'Misc' and some others

0
Why did you hook up a server script to do it? It's just to open a gui on someones UI. hiimgoodpack 2009 — 6y
0
you don't need remote events for this since it only changes what one player sees abnotaddable 920 — 6y
0
Originally I had it like Viking359 161 — 6y
0
a four line mousebutton1click where it just cloned it from the serverstorage but that didnt work with FE Viking359 161 — 6y

1 answer

Log in to vote
0
Answered by
movsb 242 Moderation Voter
6 years ago
Edited 6 years ago

You don't have a debounce in your client code.

You should add a debounce, into your client code; the debounce is to limit how often the function connected to the click event can be executed.

local ShowGui = game.ReplicatedStorage.Menu

local debounce = false;

script.Parent.MouseButton1Click:Connect(function()
    if not debounce then
        debounce = true;
        ShowGui:FireServer()
        wait(0.2);
        debounce = false;
    end
end)

Without the debounce, there is no telling how many times your script will end up firing to the server to create a new GUI.

To add, if the UI you are dealing with is only to remain over the client, then it is not necessary to execute cloning and such over the server. In FE local scripts can manage things such as UI (i.e. GUI, and sound), the client character's animation, and the client character's movement.

You should also be sending distinct information to the server from your ShowGui remote event if it is true that you are firing it for more than one purpose.

A remote event does not only fire the local player over to the server, it also fires some optional input specified by you.

Server:

local ShowGui = game:GetService("ReplicatedStorage").Menu

ShowGui.OnServerEvent:Connect(function(player, my_input)
    if my_input == "input" then --create a new menu only if the sent input is equal to the string "input"
        game.ServerStorage.GUI.TheMenu:Clone().Parent = player:WaitForChild("PlayerGui")
    end
end)

Client:

local ShowGui = game.ReplicatedStorage.Menu

local debounce = false;

script.Parent.MouseButton1Click:Connect(function()
    if not debounce then
        debounce = true;
        ShowGui:FireServer("input") --the input you send will tell the server that you want to create one menu whenever it recieves "input"
        wait(0.2);
        debounce = false;
    end
end)

Of course you can always change what input you are sending to the server and such.

0
That wasn't the problem, I'm pretty sure it's firing other remote events than 'Menu'. Debounce will help in general, though. Viking359 161 — 6y
0
@Viking you know you can use a variable number of parameters after the player for input from the client to the server right? I will edit my answer to show you. movsb 242 — 6y
0
It turns out that the problem was that I had set several gui to fire when 'Menu' was fired rather than their own event. I had forgotten that I could use multiple parameters though, so thanks for reminding me. Viking359 161 — 6y
Ad

Answer this question