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

How to copy a frame into PlayerGui?

Asked by 4 years ago
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

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

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)
0
Still get error: Players.Sasha_Syshenko.PlayerGui.ScreenGui.TextButton.LocalScript:4: attempt to index local 'Player' (a nil value) Sasha_Syshenko 20 — 4y
0
I have edited my post. I forgot to remove the `Player` inside the function parameters at line 3 Twinbrotato 543 — 4y
Ad

Answer this question