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

LINE 3 invalid argument #2 (string expected, got Instance)?

the value is a string value


script.Parent.OnServerEvent:Connect(function(player, Item, StorageSlot)
	local SlotToStore = StorageSlot
	if player.SafeStats[SlotToStore].Value == "Empty" then

		player.SafeStats[SlotToStore].Value = Item
		
		
		if player.Backpack:FindFirstChild(Item):FindFirstChild("Clips") then
			player.SafeStats[SlotToStore].SS.Value = player.Backpack:FindFirstChild(Item):FindFirstChild("Clips").Value
		end
		
		player.Backpack:FindFirstChild(Item):Destroy()
		script.Parent.Parent.Parent:Remove()
	end
end)

1 answer

You're probably comparing a StringValue named Value to a string, try adding the Value property.

script.Parent.OnServerEvent:Connect(function(player, Item, StorageSlot)
    local SlotToStore = StorageSlot
    if player.SafeStats[SlotToStore].Value.Value == "Empty" --[[Better!]] then

        player.SafeStats[SlotToStore].Value.Value = Item


        if player.Backpack:FindFirstChild(Item):FindFirstChild("Clips") then
            player.SafeStats[SlotToStore].SS.Value = player.Backpack:FindFirstChild(Item):FindFirstChild("Clips").Value
        end

        player.Backpack:FindFirstChild(Item):Destroy()
        script.Parent.Parent.Parent:Remove() --Remove is deprecated, try using alternatives such as .Parent = nil or :Destroy()
    end
end)

4 comments

0

this is the system, safestats is a folder inside the player, [SlotToStore] is a value inside the folder, line 3 basically is saying that if the value is equal to empty then it fires all the other lines

0

equal to empty sorry, typo.

0

alright i just tried it and, im getting this now 3: invalid argument #2 (string expected, got Instance)

0

I think found the problem! StorageSlot is probably an Instance and not a string. Check :FireServer() and see if StorageSlot is a string or an Instance.

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