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

bad argument #3 to 'Value' (string expected, got Object), how to fix?

On line 13, it fails. I've tried to make the 'Shirt' class an ObjectValue, currently a StringValue, but it would give another error saying that line 15: bad argument #2 to '?' (string expected, got Object). How can I fix this?

local player = script.Parent.Parent.Parent.Parent.Parent.Parent
local Shirt = player:WaitForChild("Shirt")
local shirtFolder = game:GetService("ReplicatedStorage"):WaitForChild("Shirts")

local shirts = {}
local Count = 1

local LB = script.Parent:WaitForChild("Left")
local RB = script.Parent:WaitForChild("Right")

function Update()
	script.Parent.Parent.Parent:WaitForChild("TitleShirt").Text = shirts[Count].Name
	Shirt.Value = shirts[Count]
	
	local clone = game.ReplicatedStorage.Shirts[Shirt.Value]:Clone()
	player.Character.Shirt:Remove()
	clone.Parent = player.Character
end

for i,v in pairs(shirtFolder:GetChildren()) do
	table.insert(shirts,v)
end

LB.MouseButton1Click:connect(function()
	if Count > 1 then
		Count = Count - 1
		Update()
	end
end)

RB.MouseButton1Click:connect(function()
	if Count >= #shirts then
	else
		Count = Count + 1
		Update()
	end
end)

1 answer

✓ Accepted answer

If it is a StringValue then just add on .Name

So basically

 Shirt.Value = shirts[Count].Name

This does depend on how you put items into your array, if you put it straight as an object, the above line should work.

You could instead change line 21 to

table.insert(shirts,v.Name)

And leave line 13 the same.

This should work if your trying to change the value of a StringValue.

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