So I have a basic part, I scripted that when you click the part, a GUI pops up (card giver gui) and you fill in the info, etc. When the card has been given to the user, I go and click back the part, the GUI won't open, it's like a one time thing, how can I make it that when I re-click the GUI numerous times, it will open up?
--Variables MainScreen = script.Parent.GUI.CardGiverGui MainScreen = script.Parent.GUI.CardGiverGui XButton = script.Parent.GUI.CardGiverGui.Main.X function onClicked() MainScreen:Clone() MainScreen.Parent = game.Players.LocalPlayer.PlayerGui end
Includes; Click detector and GUI folder with the card giver GUI
Please help me out!
Sincerely, MPotterhead
MainScreen is declared twice. No reason to do that.
MainScreen:Clone() is a function that returns the cloned object. To use :Clone() properly, you would declare another variable as MainScreen:Clone().
You're moving the original MainScreen into the player's PlayerGui. Move the clone instead.
Fixed script:
--Variables MainScreen = script.Parent.GUI.CardGiverGui XButton = script.Parent.GUI.CardGiverGui.Main.X function onClicked() local screenClone = MainScreen:Clone() screenClone.Parent = game.Players.LocalPlayer.PlayerGui end
So, all guis need to run on the client, great, local script! but wait, ClickDetectors don't work on a local script, only on a server script
How do we fix this?
We use a little thing called Remote events
What's a remote event?
For a short description, it basically sends stuff to the other side, useful for FE games.
So, in ReplicatedStorage, insert a RemoteEvent, name it whatever you want, and in a local script where you will manage the gui,
--LOCAL SCRIPT local plr = game.Players.LocalPlayer --so we can get the plrgui easier, local gui = --post where it is game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function() --We are waiting until the server script fires this, when it does it will run --Now we should move the gui into the player Gui --if you want to clone it, then here local new = gui:Clone() new.Parent = plr.PlayerGui --If it's already in plrgui, then just make it visible (if it's not) gui.Visible = not gui.Visible end)
Now, we shall fire this client event through the server script
--SERVER SCRIPT local cd = --post where the click detector is local re = game.ReplicatedStorage.RemoteEvent cd.OnClicked:Connect(function(player) --I don't actually know what event it has, my bad if its wrong --If you don't know, I am doing an anonymous function, basically without a name. re:FireClient(player) end)
I HAVE NOT TESTED THIS IN STUDIO, I DON'T KNOW IF ANYTHING WILL ERROR
Hope this helps! If it does, make sure to accept this answer! If not, please comment what's wrong and I'll try my best to fix it!
Any other concerns, or comments, make sure to post below and I'll try my best to answer!
-John