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

attempt to index field 'Parent' (a nil value) How do i fix this?

There is an error at line 9. I am trying to make a tool that give cash and that is the fill of the tool. I hope you understand me.

local prog = 0
local Give = workspace.Events.Give
local Player = game.Players.LocalPlayer
local fillv = game.ReplicatedStorage.Fillit
local x = 	script.Parent.Parent.Parent
Player.Backpack.Cash1.Activated:Connect(function()
	while wait(.1) do
	prog = prog + 10
	script.Parent.Size = UDim2.new(prog/100, 0, 0, 65)
	script.Parent.Text = ("Filling...")
	if prog == 100 then
		wait(0.34)
		fillv.Value = false
       x:Destroy()
	end
	end
end)

1 answer

✓ Accepted answer

The problem is on line 14 where you destroy the variable x. When you destroy something, it also gets rid of all of its children. From line 5 you can see that variable x is a parent of the script so when you destroy it, it would get rid of everything beneath it including the script itself and the parent you were trying to access.

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