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

Script that gives tools keeps giving error. How should I go around it?

script.Parent.MouseButton1Click:Connect(function(plr)
	script.Parent.Parent.Parent.frame2.Visible = false
	script.Parent.Parent.Parent.frame3.Visible = true
	wait(1)
	script.Parent.Parent.Parent.frame3.changeLabel.Text = "Verifying Details..."
	wait(1.5)
	script.Parent.Parent.Parent.frame3.changeLabel.Text = "Printing Card..."
	local tool = game.Lighting.Passport
	local clone = tool:Clone()
	clone.Parent = plr.Backpack
	wait(0.5)
	script.Parent.Parent.Parent.frame3.changeLabel.Text = "Check-In Complete!"
end)

This script is trying to give a tool to a player, but I don't seem to understand any of it as I get the error: Players.Avia_Adaam.PlayerGui.ScreenGui.frame2.TextButton.Script:10: attempt to index local 'plr' (a nil value), I've tried everything and nothing works.

1 comment

1 answer

✓ Accepted answer

If it's not already, it should be in a local script. If it's in a local script like it should be, then you can just use:

local plr = game.Players.LocalPlayer

That way you don't even need to use the "plr" from the function itself, which I'm pretty sure gives nil, because it's a MouseClick function, so it's getting the mouse not the player. Although, I'm new to scripting so don't quote me on that.

4 comments

0

You are the best! It works.

0

One question how would I do the reverse and take away the tool?

0

You should be able to use .Parent to change where it's located. So, for example, you could make a folder in ServerStorage and do tool.Parent = ServerStorage.(Folder Name).

0

Ok!

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