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

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

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)

4 comments

0

change item at line 11 to item.Name. item is an instance, item.Name is the instances name, which is a string.

0

the error says it all, game.ReplicatedStorage.Items.Value is a string value. item is an instance, so it gave you that error

0

the value expected a string (which in this case is the item's name), but the value got an instance (the item itself).

0

oh my gosh, how did i miss that? thank you so much!

1 answer

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

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