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

ScreenGUI to give items [ HAS ERRORS ] (attempt to index local 'plr')?

I need some help for making a ScreenGUI give items to a player. I have tried but it gives me this error: 16:22:57.454 - Players.Pixelated_DAKING.PlayerGui.ScreenGui.Frame.TextButton.LocalScript:4: attempt to index local 'plr' (a nil value). I even tried putting "Player" and "LocalPlayer" instead of "plr".

local gear = game.Lighting.Keycards["[SCP] Card-L1"]

function Click(mouse, plr)
	gear:Clone().Parent = plr:WaitForChild("Backpack")
end

script.Parent.MouseButton1Click:connect(Click)

This is for an Admin GUI for a SCP game (Keycards). Can someone please help me?

1 answer

✓ Accepted answer

The MouseButton1Click Event doesn't return a player. You can get the LocalPlayer by using

game:GetService("Players").LocalPlayer

Use this:

local gear = game.Lighting.Keycards["[SCP] Card-L1"]

function Click()
	local plr = game:GetService("Players").LocalPlayer
    gear:Clone().Parent = plr:WaitForChild("Backpack")
end

script.Parent.MouseButton1Click:connect(Click)

1 comment

0

Thank you!

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