hey, developers. i am making a tower defense game and im stuck in this code which I want to reference the String value that is stored in the LocalPlayer and i want to put the string values which is the tower names into the hotbar in StarterGui but it keeps giving me this error again and again
for i, v in pairs(game.Players.LocalPlayer:GetChildren()) do wait(1) if v:IsA("StringValue") then player[v.Name].Changed:Connect(function() wait(1) print(v) print(v.Name) print(v.Value) local TowerName = v script.Parent[v].TowerName.Value = TowerName:WaitForChild("Value") end) end end
the error is
Players.DaRealHotSauce.PlayerGui.Hotbar.HotbarFrame.Monitor:20: invalid argument #2 (string expected, got Instance) - Client - Monitor:20
this line of code specifically is the one that is giving me the error
script.Parent[v].TowerName.Value = TowerName:WaitForChild("Value")
if you can figure out why it’s broken, please leave a suggestion. also, i’m very new to scripting.
v
is Instance, you probably meant v.Name
, :WaitForChild
will also return an Instance, .Value
is a property that holds string value of the value:
script.Parent[v.Name].TowerName.Value = TowerName:WaitForChild("Value").Value
And your TowerName
variable is misleading since it's Instance while name should be mostly represented by string >:v