Attempted to index nil with 'Name' issue in a shop script

I used a sim shop model from alvinblox and tried to modify it and customize it to my liking, one problem, all of a sudden this started popped up in the output: Attempted to index nil with ‘Name’. Why is this happening?

boxName:GetPropertyChangedSignal(“Value”):Connect(function()

local model = nil

for i, object in pairs(game.Workspace.ItemRoller[“Box”…boxName.Value]:GetChildren()) do

  if object:IsA("Model") then
  	model = object -- Swtting the model variable to the object
  end

end

local toolsBought = game.ReplicatedStorage.GetToolsBought:InvokeServer()

for i, tool in pairs(toolsBought) do

  if tool == model.Name then --ISSUE HERE
  	-- Already bought by the player
  	
  	script.Parent.Text = "Equipped"
  else
  	script.Parent.Text = "Equip"
  	
  end

end

end)

it says attempted to index nil with name yet the model clearly exists and does have a name property…?

you search all the objects in for i, object in pairs(game.Workspace.ItemRoller[“Box”…boxName.Value]:GetChildren()) do

but i dont see what boxName is

local boxName = script.Parent.Parent.Parent.CurrentBox

Screenshot_50

is the script in the localscript i see in the screen shot?

Screenshot_51

or could I just send you the whole model that I used?

well your issue is at model.Name
so my gues would be that model = object never happend

try changing this

 if object:IsA("Model") then
  	model = object -- Swtting the model variable to the object
  end

to

 if object:IsA("Model") then
  	model = object -- Swtting the model variable to the object
print("switched the model")
  end

and if you run this see if the output says “switched the model”

looked in the output, didnt print anything…

this can have 2 causes
1: it is searching in the wrong folder
2: there is no “model” in that folder

OH, I managed to fix it. There was a folder that would display the tool models and for some reason the tools were not anchored, meaning they just fell through the floor and dissappeared which is what caused the issue. I’m so sorry for all the trouble.

glad we could help ^^

i need a minimum of chars to reply

1 Like