Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to copy a frame into PlayerGui?

script.Parent.MouseButton1Click:Connect(function(Player)
	game.Lighting.Frame:Clone().Parent = Player.PlayerGui
end)

I made this but i get error: Players.Sasha_Syshenko.PlayerGui.ScreenGui.TextButton.Script:2: attempt to index local 'Player' (a nil value)

1 answer

✓ Accepted answer

Player is nil because the MouseButton1Click event does not pass any arguments to the function connected to it.

What you should do instead is define Player as the local player like so:

local Player = game.Players.LocalPlayer

So your whole script would look like this:

local Player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    game.Lighting.Frame:Clone().Parent = Player.PlayerGui
end)

2 comments

0

Still get error: Players.Sasha_Syshenko.PlayerGui.ScreenGui.TextButton.LocalScript:4: attempt to index local 'Player' (a nil value)

0

I have edited my post. I forgot to remove the Player inside the function parameters at line 3

This discussion is preserved as it was. New answers, comments, and votes are closed.