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

How can i use a normal script, to clone a gui?

Asked by 4 years ago

I want the gui to be seen by everyone, but I cant find a way to put it into everyones player gui. This is my code

script.Parent.MouseButton1Click:Connect(function(player)
local LobbyCopy = game.Lighting.LobbyGui:Clone()
LobbyCopy.Parent = player.PlayerGui
end)

I'm getting this error 17:11:32.866 - Players.Wilbyte.PlayerGui.CreatingLobbyGui.LobbyCreate.Create.Script:3: attempt to index local 'player' (a nil value) Any help would be appreciated!

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Hi! Unlike a clickdetector you can not detect who clicked a GUI, which is why people use local scripts for them.

So first, make a local script, then make this the code

script.Parent.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
local LobbyCopy = game.Lighting.LobbyGui:Clone()
LobbyCopy.Parent = player.PlayerGui
end)

Even though this is only for the client, it doesn't matter, as no matter what nobody else can see your GUIs. If you really want, you could use a remote event to do this, for example, if you need to access the gui from a server script. In that case, Make a remote event in ReplicatedStorage, Call it "RemoteEvent" make a local script with this as the code

script.Parent.MouseButton1Click:Connect(function()
local remote = game.ReplicatedStorage.RemoteEvent
remote:FireServer()
end)

Then make a server script with this code

local remote = game.ReplicatedStorage.RemoteEvent
remote.OnServerEvent:Connect(function(player)
local LobbyCopy = game.Lighting.LobbyGui:Clone()
LobbyCopy.Parent = player.PlayerGui
end)
Ad

Answer this question