String instance can't access part's name with a player index concatenated inside of it

  1. What do you want to achieve?

I want to make a shop system, like a mining shop simulator system.

  1. What is the issue?

My string value is not being set to an instance concatenated with a string. This string value recognizes what current box i’m looking at.

currentBox.Value = itemRoller["Box"..tostring(shopIndex)].Name

This is part of my code in which currentBox is a string instance and itemRoller is a model with a child named box and a number concatenated and supposedly defined by shopIndex. The issue is though this returns the error “Players.Violet_sheer.PlayerGui.ShopSelection.Handler:40: attempt to index string with ‘Value’”

  1. What solutions have you tried so far?

I’ve tried using tostring and waitforchild but neither have worked. I also checked another post by chance and found out that you couldn’t concatenate instances which is what I originally was doing with an IntegerValue so I stopped doing that.

currentBox must be a string not a string value

-- Attempt to index string with 'Value'
-- Look for something (in the line) that has .Value
currentBox = itemRoller["Box"..tostring(shopIndex)].Name

It’s an instance in the game. It’s a StringValue.

check your script

local CurrentBox = script:WaitForChild("CurrentBox").Value -- This isn't a StringValue
print(CurrentBox.Value) -- Error

“index nil with Value” means that there is no value property of currentBox

currentBox is probably nil

it would’ve said “Attempted to index nil” if currentBox was nil

I tried playing the game while currentBox had string text in it but I got the same issue.

I printed currentbox.Value and nothing happened, but there is nothing even though I put as the value “Nothing”.

Nevermind, the line was structured wrong, but it currentbox.Value = nil now even though I have string text in it.

I found the issue, I had set currentBox = to something without adding .Value to it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.