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

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

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

Log in to vote
0
Answered by 4 years ago

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.

0
You are the best! It works. Avia_Adaam 2 — 4y
0
One question how would I do the reverse and take away the tool? Avia_Adaam 2 — 4y
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). kkkeelan999 92 — 4y
0
Ok! Avia_Adaam 2 — 4y
Ad

Answer this question