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

string expected, got Instance?

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.

6 comments

0

yeah i got the same problem

0

didn't you mean TowerName:WaitForChild("Value").Value ?

0

thanks for the help but it still doesnt work. still gives me the same error.

0

Try remove waitforchild('value'). It can be that there is a children 'Value' inside a Value Object

0

still doesnt work. still has same error

0

Well, the point of the error is that you set a value to a instance instead of a string.

1 answer

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

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