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

string expected, got Instance?

Asked by 2 years ago

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.

0
yeah i got the same problem Just_Pointless 0 — 2y
0
didn't you mean TowerName:WaitForChild("Value").Value ? imKirda 4491 — 2y
0
thanks for the help but it still doesnt work. still gives me the same error. DaRealHotSauce 0 — 2y
0
Try remove waitforchild('value'). It can be that there is a children 'Value' inside a Value Object AProgrammR 398 — 2y
View all comments (2 more)
0
still doesnt work. still has same error DaRealHotSauce 0 — 2y
0
Well, the point of the error is that you set a value to a instance instead of a string. AProgrammR 398 — 2y

1 answer

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
2 years ago

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

Ad

Answer this question