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

StringValue not setting? (attempt to index nil)

Hi, just a quick one.

I have this code:

local configuration = game.Workspace:FindFirstChild('configuration') -- folder 
local currentFoot = configuration:FindFirstChild('currentFoot').Value -- string value

currentFoot = "Right Leg"

However, the value isn't setting and I am not sure why.

Maybe useful to note that this is in a localscript. Any help is appreciated.

2 answers

You can really only use variables to get objects and such, not values.

local currentFoot = configuration:FindFirsChild('currentFoot')
currentFoot.Value = 'Right Leg'

Thank you, I have tried this and changed the code to the following:

repeat wait() until game:IsLoaded()

local configuration = game.Players.LocalPlayer.Backpack:WaitForChild('configuration')
local currentFoot = configuration:WaitForChild('currentFoot')

currentFoot.Value = "Right Leg"

print(currentFoot) -- will print "nil"
print(currentFoot.Value) -- will error "attempt to  index value with nil"

To me it doesn't make any sense because the variables are set correctly and I've added WaitForChild to the objects to be sure. Then I have also added the first line to make sure the game is loaded.

1 comment

0

game.IsLoaded is set to true before all of the scripts (Except the ones in ReplicatedFirst) run so it's completely useless in your case

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