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

How do I clone a gui to all players?

Asked by 5 years ago

This is the current script.

I'm trying to create a system where a button is pressed, it will clone a gui to everyone. It isn't showing the gui, nor is it showing any errors. How can I fix this?

0
put your players variable inside the loop. greatneil80 2647 — 5y
0
Make sure you're doing this on the server not the client, as changes on the client won't replicate to other players' games plasmascreen 143 — 5y
0
other players screens* ^ greatneil80 2647 — 5y

1 answer

Log in to vote
0
Answered by
Psudar 882 Moderation Voter
5 years ago

```lua --Local Script

--//Services

repStore = game:GetService("ReplicatedStorage")

--//Objects

CloneFrameRemote = repStore:WaitForChild("CloneFrame")

Button = script.Parent.ClickMe

function FireOurRemote()

CloneFrameRemote:FireServer() --Fires RemoteEvent

end

Button.MouseButton1Click:Connect(FireOurRemote) --When button is clicked, Fires FireOurRemote() ``` So in our local Script, all we're doing is writing a function to fire our remote event.

```lua

--//Services

serverStorage = game:GetService("ServerStorage")

repStore = game:GetService("ReplicatedStorage")

--//Objects

CloneFrameRemote = repStore:WaitForChild("CloneFrame") --Our remote event

ReplicatedFrame = serverStorage:WaitForChild("ReplicateThis") --the Gui object we want to clone

--//Functions

function CloneGui()

local tablePlayers = game.Players:GetPlayers() --Once function is fired, gathers all the players into a table

for i, v in pairs (tablePlayers) do

local FrameParent = v.PlayerGui.ScreenGui --Getting ScreenGui from the players

local ClonedGui = ReplicatedFrame:Clone() --Clones the frame in ServerStorage

ClonedGui.Parent = FrameParent --Setting the parent to every players ScreenGui

wait(1)

end

end

--//Events

CloneFrameRemote.OnServerEvent:Connect(CloneGui) --When the remoteEvent is fired, we connect CloneGui() ```

In our server script, we've referenced our UI objects and our remoteEvents. First, we created a function that gets a table of all the players currently in the game. Then, we get the ScreenGui of every Player in the table. After that, we clone the Frame from the ServerStorage, and parent it to every player in the table. (This works because when we clone it, there's no parent for it. It's kinda sitting in a void. We've basically created a new clone every-time the loop goes though, and parent that clone to another player.)

I tested this with 2 players and it works, so presumably, this should also work for more players. I'll also post a pic of the hierarchy in case you need help w/ that. I'm not sure this is the best way to do this, but this is what I came up with in like the last 30 mins. There's surely a better one.

Also, I should note that normally I'd use moduleScripts for a lot of this, but for the sake of the post, here ya go :)

And if there is any misinformation here, terribly sorry. I'm also learning too. Just let me know if anything is wrong :thumbsup:

!Hierarchy for script

0
e sorry for the weird indentations, thats the result of the website format. sorry! Psudar 882 — 5y
Ad

Answer this question