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

Why am I getting this error when I try to rename a value?

Asked by 2 years ago

Im trying to store the name of a part in a string variable. but I keep getting this error: Players.Paczki_TCBC.PlayerScripts.LocalScript:35: invalid argument #3 (string expected, got Instance)

here's the part of my script that is broke:

UIS.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode[pickupkey] then
        if mouse.Target then
            if mouse.Target:FindFirstChild("Pickable") then
                local item = mouse.Target
                if item then
                    local distanceFromItem = player:DistanceFromCharacter(item.Position)
                    if distanceFromItem < 7 then
                        -- we fill this in loadstring
                        print("poopy")
                        game.ReplicatedStorage.Items.Value = item -- THIS IS THE TROUBLSOME LINE
                        PickupItem:FireServer(item)
                    end
                end
            end
        end
    end
end)
0
change item at line 11 to item.Name. item is an instance, item.Name is the instances name, which is a string. NGC4637 602 — 2y
0
the error says it all, game.ReplicatedStorage.Items.Value is a string value. item is an instance, so it gave you that error NGC4637 602 — 2y
0
the value expected a string (which in this case is the item's name), but the value got an instance (the item itself). NGC4637 602 — 2y
0
oh my gosh, how did i miss that? thank you so much! surviarlTheJefkillre 55 — 2y

1 answer

Log in to vote
0
Answered by
CDXKIE 130
2 years ago

As NGC4637 said, item is an instance. The value is a string, so you'd want to do item.Name

Ad

Answer this question