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

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

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)

2 comments

0

wait wheres the error

0

btw u should check wether u got the right number of parent

2 answers

✓ Accepted answer

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)

4 comments

0

Use variables :/

0

Use game.Players.LocalPlayer. is better

0

Thanks

0

I will try it later

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! :)

1 comment

0

y is there player:WaitForChild("Backpack") on line 2

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