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

Im getting a "Attempt to Index Nil Value" Error?

Asked by 6 years ago

Hello, I was scripting a surface gui. The surface gui is a kiosk for my aracde card. Heres the script. If you need more info ask in the answer thing.

playername = script.Parent.Parent.Parent.Parent.Parent.PlayerName.Value
script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Parent.Tickets.Ticket.Text = game.Players:FindFirstChild(playername).Backpack.Card.Tickets.Value
    script.Parent.Parent.Parent.Buttons.Visible = false
    script.Parent.Parent.Parent.Tickets.Visible = true
end)
0
wait wheres the error TheluaBanana 946 — 6y
0
btw u should check wether u got the right number of parent TheluaBanana 946 — 6y

2 answers

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

Assuming that you're trying to get the player's name who clicked on the button:

script.Parent.MouseButton1Click:Connect(function(player)--you can get the player who clicked it
    script.Parent.Parent.Parent.Tickets.Ticket.Text =       
    player.Backpack.Card.Tickets.Value
    script.Parent.Parent.Parent.Buttons.Visible = false
    script.Parent.Parent.Parent.Tickets.Visible = true
end)
0
Use variables :/ User#5423 17 — 6y
0
Use game.Players.LocalPlayer. is better yHasteeD 1819 — 6y
0
Thanks dizzyjamison08 30 — 6y
0
I will try it later dizzyjamison08 30 — 6y
Ad
Log in to vote
1
Answered by
yHasteeD 1819 Moderation Voter
6 years ago
Edited 6 years ago

Remember, in all variables use local VARIABLE not VARIABLE the local is more efficient

For first, you can get the player with game:GetService("Players").LocalPlayer (Only works in LocalScript), and you can simple use player:WaitForChild("Backpack").Card.Tickets.Value. And use player:WaitForChild("Backpack") for no errors.

You can see of WaitForChild here: Roblox Wiki - WaitForChild

You can use this:

local player = game:GetService("Players").LocalPlayer
player:WaitForChild("Backpack")

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.Parent.Tickets.Ticket.Text = player:WaitForChild("Backpack").Card.Tickets.Value
    script.Parent.Parent.Parent.Buttons.Visible = false
    script.Parent.Parent.Parent.Tickets.Visible = true
end)

Hope it helped! :)

0
y is there player:WaitForChild("Backpack") on line 2 User#23365 30 — 6y

Answer this question