Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

StringValue not setting? (attempt to index nil)

Asked by
0te 35
4 years ago

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

Log in to vote
0
Answered by
sngnn 274 Moderation Voter
4 years ago

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

local currentFoot = configuration:FindFirsChild('currentFoot')
currentFoot.Value = 'Right Leg'
Ad
Log in to vote
0
Answered by
0te 35
4 years ago

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.

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 imKirda 4491 — 4y

Answer this question